问题
Here's the code, it works if I right click on the new .Lnk and remove the quotes
from "C:\Windows\System32\control.exe /name Microsoft.Windowsupdate"
to C:\Windows\System32\control.exe /name Microsoft.Windowsupdate
echo off
Cls
set SCRIPT="%TEMP%\%RANDOM%-%RANDOM%-%RANDOM%-%RANDOM%.vbs"
echo Set oWS = WScript.CreateObject("WScript.Shell") >> %SCRIPT%
echo sLinkFile = "%USERPROFILE%\Desktop\Weekly Maintenance\Windows Update.lnk" >> %SCRIPT%
echo Set oLink = oWS.CreateShortcut(sLinkFile) >> %SCRIPT%
echo oLink.TargetPath = "C:\Windows\System32\control.exe /name Microsoft.Windowsupdate" >> %SCRIPT%
echo oLink.Save >> %SCRIPT%
cscript /nologo %SCRIPT%
del %SCRIPT%
pause
cscript /nologo %SCRIPT%
del %SCRIPT%
any ideas?
回答1:
The documentation on WshShortcut.TargetPath says:
This property is for the shortcut's target path only.
Any arguments to the shortcut must be placed in the Argument's property.
The fragment of a working code:
echo oLink.TargetPath = "C:\Windows\System32\control.exe" >> %SCRIPT%
echo oLink.Arguments = "/name Microsoft.Windowsupdate" >> %SCRIPT%
And the entire fixed code:
@echo off
Cls
set SCRIPT="%TEMP%\%RANDOM%-%RANDOM%-%RANDOM%-%RANDOM%.vbs"
echo Set oWS = WScript.CreateObject("WScript.Shell") >> %SCRIPT%
echo sLinkFile = "%USERPROFILE%\Desktop\Weekly Maintenance\Windows Update.lnk" >> %SCRIPT%
echo Set oLink = oWS.CreateShortcut(sLinkFile) >> %SCRIPT%
echo oLink.TargetPath = "C:\Windows\System32\control.exe" >> %SCRIPT%
echo oLink.Arguments = "/name Microsoft.Windowsupdate" >> %SCRIPT%
echo oLink.Save >> %SCRIPT%
cscript /nologo %SCRIPT%
del %SCRIPT%
pause
来源:https://stackoverflow.com/questions/31814060/create-a-shortcut-with-parameters-added-to-the-program-path