Issues with Target Path in powershell in creating a short cut

后端 未结 1 1842
醉梦人生
醉梦人生 2021-01-24 04:01

I am trying to create a short cut on public desktop for users, but this target path for this short cut is causing some issues.



        
相关标签:
1条回答
  • 2021-01-24 04:13

    Quote from CreateShortcut method documentation:

    A common problem is putting arguments in the TargetPath property of the shortcut object, which doesn't work. All arguments to the shortcut must be put in the Arguments property.

    So you have to do this:

    $wshshell = New-Object -ComObject WScript.shell
    
    $desktop = [System.Environment]::GetFolderPath('Desktop')
    
    $lnk = $wshshell.CreateShortcut((Join-Path -Path $desktop -ChildPath 'CLMCPDEDEV.lnk'))
    
    $lnk.TargetPath = 'C:\Program Files (x86)\Unisys\WebEnabler\Web Enabler.exe'
    $lnk.Arguments = 'configfile=c:\development-installs\web-enabler-config\CLMCPDEDEV.cfg'
    
    $lnk.Save()
    
    0 讨论(0)
提交回复
热议问题