Powershell 2.0 在PowerShell控制台中创建运行脚本的快捷方式并使链接可执行

Powershell 2.0 在PowerShell控制台中创建运行脚本的快捷方式并使链接可执行,powershell-2.0,desktop-shortcut,Powershell 2.0,Desktop Shortcut,然后将链接保存在C:\Users\Public\Desktop中,以便于访问 我该怎么做呢 基本上,原始PowerShell脚本必须创建指向自身的快捷链接,并将其保存在Public\Desktop文件夹中,并且在单击后必须在PowerShell中可执行(不在记事本中打开) 非常感谢您的帮助 您必须在提升的控制台中运行它: "greetings from PS !" $mypath=$MyInvocation.myCommand.definition $app="%windir%\system3

然后将链接保存在C:\Users\Public\Desktop中,以便于访问

我该怎么做呢

基本上,原始PowerShell脚本必须创建指向自身的快捷链接,并将其保存在Public\Desktop文件夹中,并且在单击后必须在PowerShell中可执行(不在记事本中打开)


非常感谢您的帮助

您必须在提升的控制台中运行它:

"greetings from PS !"

$mypath=$MyInvocation.myCommand.definition
$app="%windir%\system32\WindowsPowerShell\v1.0\powershell.exe"
$WshShell = New-Object -ComObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut("C:\Users\Public\Desktop\autogenerated.lnk")
$Shortcut.TargetPath = $app
$Shortcut.Arguments ="-noexit -file $mypath"
$Shortcut.Description ="autogenerated shortcut from ps"
$Shortcut.Save()

非常感谢。这非常有效,分解代码并研究它是如何工作的也是一次学习经验。我很高兴这对您有所帮助