windowsvbscriptwindows-2000

Apply userprofile into a path


I need to get a computer's user folder name and put it into a path, in this case startup and desktop path. I figured out how to find the user folder name, but I'm stuck on figuring out how to put that into a path. Anyone know how to?

Set WshShell = CreateObject("WScript.Shell")
Set WshSysEnv = WshShell.Environment("PROCESS")

It would be a great help.

EDIT

Set objShell = Wscript.CreateObject("Wscript.Shell")
strPath = objShell.SpecialFolders("Startup")
wscript.echo strPath
dim WSHShell, desktop, pathstring, startup, objFSO
set objFSO=CreateObject("Scripting.FileSystemObject")
Set WSHshell = CreateObject("WScript.Shell")
desktop = WSHShell.SpecialFolders("Desktop")
pathstring = objFSO.GetAbsolutePathName(desktop)
WScript.Echo desktop
set filesys=CreateObject("Scripting.FileSystemObject") 
filesys.CopyFile "desktop", dolpis.vbs,"startup", dolpis.vbs
set objFso=createObject("scripting.fileSystemObject")
set objWShell=wScript.createObject("WScript.Shell")
usrName=objWShell.expandEnvironmentStrings("%USERNAME%")
if objFso.folderExists(strFolder) then
   objFso.copyFile strFileToCopy,strFolder&"\",True
else
   msgbox "The folder " & strFolder & " does not exist"
end if
CreateObject("WScript.Shell").Run("C:\WINNT\system32\notepad.exe")
Set wshshell = wscript.CreateObject("WScript.Shell") 

Line 11 states "Object Required: Dolpis"


Solution

  • The property of SpecialFolders of the WshShell object provides references to Windows special folders (Desktop, Favorites, etc ...)

    List of Windows special folders available:

    1. AllUsersDesktop
    2. AllUsersStartMenu
    3. AllUsersPrograms
    4. AllUsersStartup
    5. Desktop
    6. Favorites
    7. Fonts
    8. MyDocuments
    9. NetHood
    10. PrintHood
    11. Programs
    12. Recent
    13. SendTo
    14. StartMenu
    15. Startup
    16. Templates

    Set WshShell = CreateObject("WScript.Shell")
    wscript.echo "Desktop Folder = " & WshShell.SpecialFolders("Desktop")
    wscript.echo "Startup Folder = " & WshShell.SpecialFolders("Startup")
    
    For i = 0 to WshShell.SpecialFolders.Count -1 
         sf = sf & WshShell.SpecialFolders(i) & vbCr 
    Next 
    wscript.echo "Special folders of Windows : " & vbCrlf & vbCrlf & sf 
    

    EDIT

    Option Explicit
    Dim WshShell,Desktop,Startup
    Set WshShell = CreateObject("WScript.Shell")
    Desktop = WshShell.SpecialFolders("Desktop")
    Startup = WshShell.SpecialFolders("Startup")
    wscript.echo Desktop
    wscript.echo Startup