Create a shortcut with parameters added to the program path

柔情痞子 提交于 2020-01-11 10:42:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!