获取桌面路径
2020-5-2 乱云飞
第一种方法 @echo 桌面目录路径是:%USERPROFILE%\Desktop 第二种方法 @for /f "tokens=2,*" %%i in ('reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "Desktop"') do (@set desk=%%j) @echo 桌面路径是:%desk% 第三种方法 @%1mshta vbscript:createobject("wscript.shell").run("""%~0"" : "^&createobject("wscript.shell").specialfolders("desktop"))(close) & exit /b @echo 桌面路径是:%2 ----------------------------------------------- 公共用户桌面路径 C:\Users\Public\Desktop\ 当前用户桌面路径 C:\Users\%username%\Desktop\本文链接:http://80c.cc/ez/303.html
评论:
@ echo off
set "reg=hkcu\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"
for /f "tokens=2*" %%a in ('reg query "%reg%" ^| findstr /i "\<desktop\>"') do (
copy "d:\test.txt" "%%b\"
)
当然,直接判断也可以:
if exist "%USERPROFILE%\桌面\" (
copy "d:\test.txt" "%USERPROFILE%\桌面\"
) else copy "d:\test.txt" "%USERPROFILE%\desktop\"
或者,调用mshta方法:
@ echo off
%1mshta vbscript:createobject("wscript.shell").run("""%~0"" : "^&createobject("wscript.shell").specialfolders("desktop"))(close) & exit /b
copy "d:\test.txt" "%2\"
pause