Resources for IT Professionals > 論壇首頁 > Windows PowerShell > How to create shortcut in startup menu using powershell?
發問發問
 

已答覆How to create shortcut in startup menu using powershell?

  • Monday, 29 June, 2009 18:53Leonjl 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    Hi,

    Can anybody tell me how to create shortcut in startup menu using powershell?

    I found some samples about how to do this using VBS but I prefer powershell. :)

    Thanks
    Leon

解答

  • Monday, 29 June, 2009 21:04Vadims PodansMVP使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     已答覆包含代碼
    $objShell = New-Object -ComObject ("WScript.Shell")
    $objShortCut = $objShell.CreateShortcut($env:USERPROFILE + "Start Menu\Programs\Startup" + "\program.lnk")
    $objShortCut.TargetPath("path to program")
    $objShortCut.Save()
    this will create link from scratch.
    [тут могла быть ваша реклама] http://www.sysadmins.lv

所有回覆

  • Monday, 29 June, 2009 19:18Marco ShawMVP, 版主使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    I think these are typically .lnk files.  I don't think PowerShell can easily create these...  Unless you have an existing .lnk file, and you simply want to copy it to a new folder, you may need to refer to the VBS code.

    It possibly uses WScript, and you may want to use an interface to WScript for this...

    So the important question is...  Do you already have an .lnk file, and just need to copy it? Or do you need something from scratch?
  • Monday, 29 June, 2009 21:04Vadims PodansMVP使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     已答覆包含代碼
    $objShell = New-Object -ComObject ("WScript.Shell")
    $objShortCut = $objShell.CreateShortcut($env:USERPROFILE + "Start Menu\Programs\Startup" + "\program.lnk")
    $objShortCut.TargetPath("path to program")
    $objShortCut.Save()
    this will create link from scratch.
    [тут могла быть ваша реклама] http://www.sysadmins.lv
  • Tuesday, 30 June, 2009 20:40MozillaKilled 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    I think you can do this with the PSCX  extensions package.
  • Thursday, 2 July, 2009 3:36Mervyn ZhangMSFT, 版主使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    Hi,

    Detailed explanation for Vadims script:

    http://www.microsoft.com/technet/scriptcenter/topics/winpsh/convert/wshsave.mspx

    Thanks.

    This posting is provided "AS IS" with no warranties, and confers no rights.