[英]Batch variable with variable inside of it
我正在批量制作一个程序来轻松设置IP设置,但出现错误。
这导致了问题:
for /f "usebackq tokens=3* skip=2" %%D IN (`reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v Desktop`) do set desktop=%%D
所以这提供了一个错误:
powershell "$s=(New-Object -COM WScript.Shell).CreateShortcut('%desktop%\IP Configurator.lnk');$s.TargetPath='%0';$s.IconLocation = 'C:\Windows\System32\Shell32.dll,273';$s.Save();$bytes = [System.IO.File]::ReadAllBytes('%desktop%\IP Configurator.lnk');$bytes[0x15] = $bytes[0x15] -bor 0x20;[System.IO.File]::WriteAllBytes('%desktop%\IP Configurator.lnk', $bytes);Write-Output 'Shortcut created (or there was an error), press a key to continue'"
但是它会输出此错误,因此会导致多个错误:
Unable to save shortcut "C:\Users\Ryan\Desktop\programs\IP_Configurator\%USERPROFILE%\Desktop\IP Configurator.lnk".
At line:1 char:235
+ ... conLocation = 'C:\Windows\System32\Shell32.dll,273';$s.Save();$bytes ...
+ ~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], DirectoryNotFoundException
+ FullyQualifiedErrorId : System.IO.DirectoryNotFoundException
我没有得到的是,它无法正确放置桌面,我认为这是因为它实际上并未计算%USERPROFILE%
是什么,而只是使用带括号的字面量来命名。 我怎样才能只读取变量值是什么?
for /f "usebackq tokens=3* skip=2" %%D IN (`reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v Desktop`) do set desktop=%%D
CALL SET "desktop=%desktop%"
ECHO %desktop%
应该通过解决%uerprofile%
来解决您的问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.