Create a shortcut with parameters added to the program path

后端 未结 1 1297
执笔经年
执笔经年 2021-01-21 19:47

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\"

相关标签:
1条回答
  • 2021-01-21 19:59

    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
    
    0 讨论(0)
提交回复
热议问题