获取桌面路径 - 洛阳翼展电脑


获取桌面路径

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

评论:

乱云飞
2020-05-02 23:53
桌面路径,中英文系统不一样,xp、win7、win8也不一样,可以通过读取注册表的方法:
@ 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

发表评论:

预ICP备10086-001号 © 翼展网/80C.CC 技术支持/洛阳翼展科技
TEL / 13213610060 QQ / 345794501
Powered by emlog