Reputation: 12189
Is there any way how to get a path from explorer.exe shell:<dir>
to a variable in batch file without using registry directly in my file?
Switches doesn't seem to be useful in this case.
Upvotes: 1
Views: 941
Reputation: 24476
You can use a Windows Script Host language to get the WshShell.SpecialFolders
property. Example batch + JScript hybrid solution (should be given a .bat extension):
@if (@CodeSection == @Batch) @then
@echo off & setlocal
call :getSpecialFolder AllUsersDesktop
echo %AllUsersDesktop%
call :getSpecialFolder Fonts
echo %Fonts%
goto :EOF
:getSpecialFolder <folderName=returnValue>
for /f "delims=" %%I in ('cscript /nologo /e:JScript "%~f0" "%~1"') do set "%~1=%%I"
goto :EOF
@end // end batch begin JScript
WSH.Echo(WSH.CreateObject('WScript.Shell').SpecialFolders(WSH.Arguments(0)));
From the MSDN documentation:
The WshSpecialFolders object is a collection. It contains the entire set of Windows special folders, such as the Desktop folder, the Start Menu folder, and the Personal Documents folder. The special folder name is used to index into the collection to retrieve the special folder you want. The SpecialFolders property returns an empty string if the requested folder (strFolderName) is not available. For example, Windows 95 does not have an AllUsersDesktop folder and returns an empty string if strFolderNameis AllUsersDesktop.
The following special folders are available:
- AllUsersDesktop
- AllUsersStartMenu
- AllUsersPrograms
- AllUsersStartup
- Desktop
- Favorites
- Fonts
- MyDocuments
- NetHood
- PrintHood
- Programs
- Recent
- SendTo
- StartMenu
- Startup
- Templates
Upvotes: 1