No announcement yet.

the comparable for %userprofile% in vbs

  • Filter
  • Time
  • Show
Clear All
new posts

  • the comparable for %userprofile% in vbs

    i was trying to make a batch file to copy a file to "שולחן העבודה"
    its not work becuse of the hebrew so im trying to do it in vb script
    this code is working fine the file is copied to the folder
    my qustion is how can i replace the path c:\documents and settings\david
    in varible like %userprofile% ???

    Const OverwriteExisting = True
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    objFSO.CopyFile "C:\test\1.txt" , "c:\documents and settings\david\שולחן העבודה\", OverwriteExisting

  • #2
    Re: the comparable for %userprofile% in vbs

    Well I'm posting this nearly a year after you asked the question, so it's probably not helping you.

    But it might help the next person who found your post while looking to answer the same question.

    I found some code here that did the trick.

    I won't repost the whole thing below, but here's the part I pulled out for my own use that included %userprofile%

    'Declare var's and objects
    Dim WshS
    Set WshS = WScript.CreateObject("WScript.Shell")
    Set fso = CreateObject("Scripting.FileSystemObject")

    'Expand Environment
    'Create const's to spare time and place
    usrProfile = WshS.ExpandEnvironmentStrings("%UserProfile%")

    ' Message to prove my string contains the path to my profile
    strMessage = usrProfile
    Msgbox strMessage, 0, "Your profile name is"
    Other useful paths are:
    'Expand Environment
    'Create const's to spare time and place
    sysr = WshS.ExpandEnvironmentStrings("%SystemRoot%")
    sysd = WshS.ExpandEnvironmentStrings("%Systemdrive%")
    home = WshS.ExpandEnvironmentStrings("%Homepath%")
    aup = WshS.ExpandEnvironmentStrings("%AllUsersProfile%")
    cpf = WshS.ExpandEnvironmentStrings("%CommonProgramfiles %")
    pf = WshS.ExpandEnvironmentStrings("%Programfiles%")
    Obviously variable names for strings are changeable.

    Hope this helps someone.