我想用PowerShell为这个可执行文件创建一个快捷方式:
C:\Program Files (x86)\ColorPix\ColorPix.exe
如何做到这一点?
发布于 2012-03-14 20:23:30
我不知道powershell中有什么本机cmdlet,但你可以使用com对象:
$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut("$Home\Desktop\ColorPix.lnk")
$Shortcut.TargetPath = "C:\Program Files (x86)\ColorPix\ColorPix.exe"
$Shortcut.Save()
您可以在$pwd中创建一个powershell脚本,另存为set-shortcut.ps1
param ( [string]$SourceExe, [string]$DestinationPath )
$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut($DestinationPath)
$Shortcut.TargetPath = $SourceExe
$Shortcut.Save()
然后这样叫它
Set-ShortCut "C:\Program Files (x86)\ColorPix\ColorPix.exe" "$Home\Desktop\ColorPix.lnk"
如果要将参数传递给目标exe,可以通过以下方法完成:
#Set the additional parameters for the shortcut
$Shortcut.Arguments = "/argument=value"
在$Shortcut.Save()之前。
为方便起见,这里是set-shortcut.ps1的修改版本。它接受参数作为它的第二个参数。
param ( [string]$SourceExe, [string]$ArgumentsToSourceExe, [string]$DestinationPath )
$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut($DestinationPath)
$Shortcut.TargetPath = $SourceExe
$Shortcut.Arguments = $ArgumentsToSourceExe
$Shortcut.Save()
https://stackoverflow.com/questions/9701840
复制相似问题