2013/02/04

Batch取得桌面路徑 Get Desktop Path In Batch

煩惱Windows Batch該如何取得桌面路徑嗎?不解釋,上Code
(Windows7, Windows XP測試通過)
@echo off

::呼叫GetDesktop
call :GetDesktop

::輸出
echo Desktop @ %desktop%

::跳到檔尾(離開Batch)
goto :EOF



:GetDesktop
reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v Desktop | find "Desktop" > o.txt
for /F "tokens=2 delims=\" %%a in (o.txt) do set "desktop=%userprofile%\%%a"
del o.txt
goto :EOF

沒有留言:

張貼留言