[英]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.