這裏是一個批處理代碼,以獲得幾個下載目錄,我認爲這是自我解釋。
此批處理代碼是在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