这里是一个批处理代码,以获得几个下载目录,我认为这是自我解释。
此批处理代码是在Windows XP 86只测试与Internet Explorer 8
@echo off
setlocal
set "Reg32=%SystemRoot%\System32\reg.exe"
if not "%ProgramFiles(x86)%"=="" "Reg32=%SystemRoot%\SysWOW64\reg.exe"
for /F "usebackq skip=4 tokens=3*" %%U in (`%Reg32% query "HKCU\Software\Microsoft\Internet Explorer" /v "Download Directory"`) do (
set "DownloadDirectory=%%V"
goto GetSaveDir
)
:GetSaveDir
for /F "usebackq skip=4 tokens=3*" %%U in (`%Reg32% query "HKCU\Software\Microsoft\Internet Explorer\Main" /v "Save Directory"`) do (
set "SaveDirectory=%%V"
goto OutputResults
)
:OutputResults
cls
echo.
echo Download directory of user account is:
echo.
echo %USERPROFILE%\Downloads
echo.
echo.
if "%DownloadDirectory:~-1%"=="\" set "DownloadDirectory=%DownloadDirectory:~0,-1%"
echo Download directory of Internet Explorer is:
echo.
echo %DownloadDirectory%
echo.
echo.
if "%SaveDirectory:~-1%"=="\" set "SaveDirectory=%SaveDirectory:~0,-1%"
echo Save directory of Internet Explorer is:
echo.
echo %SaveDirectory%
endlocal
UPDATE
但对于Windows Vista/7/8/8.1不同批次的需要作为用于下载的目录在Internet Explorer 8/9/10/11的Windows版本中定义不同。
下一批代码应该在所有的Windows操作系统运行从Windows 2000开始
它输出的硬盘(第一个),或在Windows注册表(其余三)发现的目录。
@echo off
setlocal
set "Reg32=%SystemRoot%\System32\reg.exe"
if not "%ProgramFiles(x86)%"=="" "Reg32=%SystemRoot%\SysWOW64\reg.exe"
for /F "usebackq skip=1 tokens=1,2*" %%T in (`%Reg32% query "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "{374DE290-123F-4565-9164-39C4925E467B}" 2^>nul`) do (
if /I "%%T"=="{374DE290-123F-4565-9164-39C4925E467B}" (
set "DownloadShellFolder=%%V"
goto GetDownloadDirectory
)
)
:GetDownloadDirectory
for /F "usebackq skip=1 tokens=1,2,3*" %%S in (`%Reg32% query "HKCU\Software\Microsoft\Internet Explorer" /v "Download Directory" 2^>nul`) do (
if /I "%%S"=="Download" (
if /I "%%T"=="Directory" (
set "DownloadDirectory=%%V"
goto GetSaveDirectory
)
)
)
:GetSaveDirectory
for /F "usebackq skip=1 tokens=1,2,3*" %%S in (`%Reg32% query "HKCU\Software\Microsoft\Internet Explorer\Main" /v "Save Directory" 2^>nul`) do (
if /I "%%S"=="Save" (
if /I "%%T"=="Directory" (
set "SaveDirectory=%%V"
goto OutputResults
)
)
)
:OutputResults
cls
echo.
if not exist "%USERPROFILE%\Downloads" goto OutputShellFolder
echo Download directory of user account is:
echo.
echo %USERPROFILE%\Downloads
echo.
echo.
:OutputShellFolder
if "%DownloadShellFolder%"=="" goto OutputDownloadDir
if "%DownloadShellFolder:~-1%"=="\" set "DownloadShellFolder=%DownloadShellFolder:~0,-1%"
echo Download shell folder of user account is:
echo.
echo %DownloadShellFolder%
echo.
echo.
:OutputDownloadDir
if "%DownloadDirectory%"=="" goto OutputSaveDir
if "%DownloadDirectory:~-1%"=="\" set "DownloadDirectory=%DownloadDirectory:~0,-1%"
echo Download directory of Internet Explorer is:
echo.
echo %DownloadDirectory%
echo.
echo.
:OutputSaveDir
if "%SaveDirectory%"=="" goto EndBatch
if "%SaveDirectory:~-1%"=="\" set "SaveDirectory=%SaveDirectory:~0,-1%"
echo Save directory of Internet Explorer is:
echo.
echo %SaveDirectory%
:EndBatch
endlocal
'%userprofile%\ Downloads'有什么问题? – SomethingDark 2014-12-13 15:51:00
让我怀疑PowerShell的'GetFolderPath'方法允许一个GUID作为一个有效的参数。说:可能的枚举值是“桌面,程序,个人,MyDocuments,收藏夹,启动,最近,SendTo,StartMenu,MyMusic,DesktopDirectory,MyComputer,模板,ApplicationData,LocalApplicationData,InternetCache,饼干,历史,CommonApplicationData,系统,ProgramFiles, MyPictures,CommonProgramFiles“。并且[文件夹GUID](http://msdn.microsoft.com/en-us/library/windows/desktop/dd378457(v = vs.85).aspx)的默认值为'%USERPROFILE%\ Downloads' – JosefZ 2014-12-13 16:15:59
谢谢。这只是尝试使用GUID。因为它也在“Shell文件夹”上。 – PureFox 2014-12-14 13:09:28