桌面路径的环境变量是什么? [英] What's the environment variable for the path to the desktop?
问题描述
我正在编写Windows批处理文件,并想将某些内容复制到桌面上.我想我可以用这个:
I'm writing a Windows batch file and want to copy something to the desktop. I think I can use this:
%UserProfile%\ Desktop \
%UserProfile%\Desktop\
但是,我在想,这可能只会在英语OS上起作用.我有办法在可以在任何国际化版本上运行的批处理文件中做到这一点吗?
However, I'm thinking, that's probably only going to work on an English OS. Is there a way I can do this in a batch file that will work on any internationalized version?
更新
我尝试了以下批处理文件:
I tried the following batch file:
REG QUERY "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v Desktop
FOR /F "usebackq tokens=3 skip=4" %%i in (`REG QUERY "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v Desktop`) DO SET DESKTOPDIR=%%i
FOR /F "usebackq delims=" %%i in (`ECHO %DESKTOPDIR%`) DO SET DESKTOPDIR=%%i
ECHO %DESKTOPDIR%
并获得以下输出:
S:\>REG QUERY "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v Desktop
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
Desktop REG_EXPAND_SZ %USERPROFILE%\Desktop
S:\>FOR /F "usebackq tokens=3 skip=4" %i in (`REG QUERY "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folder
s" /v Desktop`) DO SET DESKTOPDIR=%i
S:\>FOR /F "usebackq delims=" %i in (`ECHO ECHO is on.`) DO SET DESKTOPDIR=%i
S:\>SET DESKTOPDIR=ECHO is on.
S:\>ECHO ECHO is on.
ECHO is on.
推荐答案
我发现最好的解决方案是将vbscript与批处理文件一起使用.
I found that the best solution is to use a vbscript together with the batch file.
这是批处理文件:
@ECHO OFF
FOR /F "usebackq delims=" %%i in (`cscript findDesktop.vbs`) DO SET DESKTOPDIR=%%i
ECHO %DESKTOPDIR%
这是findDesktop.vbs文件:
Here is findDesktop.vbs file:
set WshShell = WScript.CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop")
wscript.echo(strDesktop)
可能还有其他解决方案,但我个人认为这种解决方法不太可靠.
There may be other solutions but I personally find this one less hackish.
我在英语PC和法语PC上都进行了测试-似乎可以运行(Windows XP).
I tested this on an English PC and also a French PC - it seems to work (Windows XP).
HTH,
尤利安(IulianŞerbănoiu)
Iulian Şerbănoiu
这篇关于桌面路径的环境变量是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!