本文介绍了如何使用Powershell创建快捷方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要为此可执行文件使用Powershell创建快捷方式:

  C:\Program Files(x86)\ ColorPix \ColorPix.exe 

如何做到这一点?




<$ p $

p> $ WshShell = New-Object -comObject WScript.Shell
$ Shortcut = $ WshShell.CreateShortcut($ Home\Desktop\ColorPix.lnk)
$快捷方式.TargetPath =C:\Program Files(x86)\ColorPix\ColorPix.exe
$ Shortcut.Save()

您可以在$ pwd

 <$ c $中创建一个PowerShell脚本并另存为set- c> param([string] $ SourceExe,[string] $ DestinationPath)

$ WshShell = New-Object -comObject WScript.Shell
$ Shortcut = $ WshShell.CreateShortcut
$ Shortcut.TargetPath = $ SourceExe
$ Shortcut.Save()

并像这样调用



Set-ShortCutC:\Program Files(x86)\ColorPix\ColorPix.exe$ Home \Desktop \ColorPix.lnk



如果要将参数传递给目标exe,可以通过: / p>

 '为快捷方式设置附加参数
$ 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()


I want to create a shortcut with Powershell for this executable:

C:\Program Files (x86)\ColorPix\ColorPix.exe

How can this be done?

解决方案

I don't know any native cmdlet in powershell but you can use com object instead:

$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut("$Home\Desktop\ColorPix.lnk")
$Shortcut.TargetPath = "C:\Program Files (x86)\ColorPix\ColorPix.exe"
$Shortcut.Save()

you can create a powershell script save as set-shortcut.ps1 in your $pwd

param ( [string]$SourceExe, [string]$DestinationPath )

$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut($DestinationPath)
$Shortcut.TargetPath = $SourceExe
$Shortcut.Save()

and call it like this

Set-ShortCut "C:\Program Files (x86)\ColorPix\ColorPix.exe" "$Home\Desktop\ColorPix.lnk"

If you want to pass arguments to the target exe, it can be done by:

'Set the additional parameters for the shortcut
$Shortcut.Arguments = "/argument=value"

before $Shortcut.Save().

For convenience, here is a modified version of set-shortcut.ps1. It accepts arguments as its second parameter.

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()

这篇关于如何使用Powershell创建快捷方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-12 11:27