2015-08-28 201 views
1

我想爲用戶創建公共桌面上的快捷方式,但此捷徑的此目標路徑導致了一些問題。PowerShell中創建快捷方式的目標路徑問題

$wshshell = New-Object -ComObject WScript.shell 

$desktop = [System.Environment]::GetFolderPath("desktop") 

$lnk = $wshshell.CreateShortcut("$desktop\CLMCPDEDEV.lnk") 

$lnk.TargetPath = "C:\Program Files (x86)\Unisys\WebEnabler\Web Enabler.exe" "configfile=c:\development-installs\web-enabler-config\CLMCPDEDEV.cfg" 

我在另一個文件夾中的配置文件和exe是在不同的路徑。我是電源外殼新手,我如何繞過"C:\Program Files (x86)\Unisys\WebEnabler\Web Enabler.exe""configfile=c:\development-installs\web-enabler-config\CLMCPDEDEV.cfg"之間的空間?當我手動完成這個時,這是完整的捷徑。任何指導非常感謝。

+0

是否把一個單引號之前' 「C:'和'後.CFG」'幫助嗎? –

回答

2

報價從CreateShortcut方法文檔:

一個常見的問題是把參數中的 快捷對象,它不起作用TARGETPATH屬性。快捷鍵 的所有參數都必須放在參數屬性中。

所以,你必須這樣做:

$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

這工作,並將捷徑公諸於衆我使用了典型的cmd/c xcopy%userprofile%\ desktop \ CLMCPDEDEV.lnk c:\ users \ public \ desktop 然後cmd/c del%userprofile%\ desktop \ CLMCPDEDEV .lnk以避免重複圖標 – joextreme

+0

Hi BeatCracker。如果我想要將公共桌面上的特定lnk更改爲快捷方式圖標,我會使用什麼命令?我在一個文件夾中有一個ICO文件,它與我想要clmcpdedev.lnk使用的顏色不同。 – joextreme

+0

不知道,走了另一條路線,謝謝 – joextreme

相關問題