Obtain the full path to any of the special Windows folders (Desktop, Start Menu etc).
Syntax strMyPath = objShell.SpecialFolders("strFolderName") or strMyPath = objShell.SpecialFolders.Item("strFolderName") Arguments: objShell A WScript.Shell object strFolderName : One of the following special folders (not all are available to all flavors of Windows) AllUsersDesktop AllUsersStartMenu AllUsersPrograms AllUsersStartup Desktop Favorites Fonts MyDocuments NetHood PrintHood Programs Recent SendTo StartMenu Startup Templates Returns: strMyPath : The full path to the special folder returns NULL if the folder is not available.
These special folders do not work in all language locales, a preferred method is to query the value from User Shell folders like this example vbscript.
Examples
Return the full path to the Windows Desktop:
'findDesktop.vbs
Dim objShell
Dim strPath
Set objShell = Wscript.CreateObject("Wscript.Shell")
strPath = objShell.SpecialFolders("Desktop")
wscript.echo strPath
A CMD batch file in the same folder can then read the Desktop location with one line:
FOR /F "delims=" %%i in ('cscript %~dp0\findDesktop.vbs //nologo') DO Set _DeskTopDir=%%i
List all special folders:
For Each strFolder In WScript.CreateObject("Wscript.Shell").SpecialFolders MsgBox strFolder Next
“An artist who was once known as Prince
On the stage he would wiggle and mince
And then, for a giggle, He changed his name to a squiggle
And nobody's heard of him since” ~ Tim Brooke-Taylor
Related
Shell: folder - Shortcuts to key folders.
User Shell Folders - Profile, Start Menu - Location of user profile folders.
Equivalent in PowerShell: environment variables or (Get-WMIObject Win32_OperatingSystem).SystemDirectory