2014-12-13 101 views
1

如何在變量中獲取Windows下載Shell文件夾?在批處理文件中獲取Windows下載文件夾的路徑(下載shell文件夾)

根據this。我試過了:

@echo off 
SETLOCAL 

FOR /F "usebackq" %%f IN (`PowerShell -NoProfile -Command "Write-Host([Environment]::GetFolderPath('{374DE290-123F-4565-9164-39C4925E467B}'))"`) DO (SET "DOWNLOAD_FOLDER=%%f") 

@ECHO %DOWNLOAD_FOLDER% 
pause 

這是行不通的。

+0

'%userprofile%\ Downloads'有什麼問題? – SomethingDark 2014-12-13 15:51:00

+0

讓我懷疑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

+0

謝謝。這只是嘗試使用GUID。因爲它也在「Shell文件夾」上。 – PureFox 2014-12-14 13:09:28

回答

0

這裏是一個批處理代碼,以獲得幾個下載目錄,我認爲這是自我解釋。

此批處理代碼是在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 
+0

謝謝。那%USERPROFILE%\ Downloads我知道。另一個我沒有。但運行批處理會出現錯誤:「命令的語法不正確 On:if」%DownloadDirectory:〜-1%「==」\「set」DownloadDirectory =%DownloadDirectory:〜0,-1%「 – PureFox 2014-12-14 13:02:00

+1

在Win7/8中,HKCU \ Software \ Microsoft \ Internet Explorer不支持對默認下載文件夾的隱藏。它位於:HKCU \ Software \ Microsoft \ Windows \ Current \ Version \ Explorer \ Shell文件夾和HKCU \ Software \ Microsoft \ Windows \ Current \ Version \ Explorer \ Shell文件夾和HKCU \ Software \ Microsoft \ Windows \ Current \ Version \ Explorer \用戶Shell文件夾並識別bij GUID:{374DE290-123F-4565-9164-39C4925E467B} – PureFox 2014-12-14 13:19:19

+0

最後一個CMD文件的作品,非常感謝,我爲我的網站寫了一篇關於下載文件夾的文章,我在其中使用了一個批處理文件,現在用戶必須指定他們自己的下載文件夾,我可以在批處理文件中使用你的解決方案嗎?當然,提到你的學分 – PureFox 2014-12-14 18:58:35

相關問題