我想創建PowerShell的快捷方式,用於該可執行文件的快捷方式:如何創建使用PowerShell
C:\Program Files (x86)\ColorPix\ColorPix.exe
如何才能做到這一點?
我想創建PowerShell的快捷方式,用於該可執行文件的快捷方式:如何創建使用PowerShell
C:\Program Files (x86)\ColorPix\ColorPix.exe
如何才能做到這一點?
我不知道在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()
您可以創建一個PowerShell腳本保存在你的$ PWD設置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"
'Set the additional parameters for the shortcut
$Shortcut.Arguments = "/argument=value"
前 $ Shortcut.Save():如果你想傳遞參數給目標exe文件,它可以這樣做。
爲方便起見,這裏是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()
開始的PowerShell 5.0 New-Item
,Remove-Item
和Get-ChildItem
已得到增強,以支持創建和管理符號鏈接。 ItemType參數New-Item
接受一個新的值SymbolicLink。現在,您可以通過運行New-Item cmdlet在一行中創建符號鏈接。
New-Item -ItemType SymbolicLink -Path "C:\temp" -Name "calc.lnk" -Value "c:\windows\system32\calc.exe"
要小心一個SymbolicLink是從快捷不同,快捷方式只是一個文件。他們有一個大小(一個小的,只是引用他們指向的地方),他們需要一個應用程序來支持該文件類型才能使用。符號鏈接是文件系統級別,所有內容都將其視爲原始文件。應用程序不需要特殊的支持來使用符號鏈接。
無論如何,如果你想創建一個以管理員身份運行快捷使用PowerShell可以使用
$file="c:\temp\calc.lnk"
$bytes = [System.IO.File]::ReadAllBytes($file)
$bytes[0x15] = $bytes[0x15] -bor 0x20 #set byte 21 (0x15) bit 6 (0x20) ON (Use –bor to set RunAsAdministrator option and –bxor to unset)
[System.IO.File]::WriteAllBytes($file, $bytes)
如果有人想改變別的東西,你可以參考official Microsoft documentation .lnk文件。
開始PowerShell 5.0 New-Item,Remove-Item和Get-ChildItem已得到增強以支持創建和管理符號鏈接[請參閱此答案](http://stackoverflow.com/a/29002672/608772) – JPBlanc 2015-03-12 06:12:41
如果你想運行一個快捷方式作爲管理員,你可以使用[這個答案](http://stackoverflow.com/a/29002207/608772)。 – JPBlanc 2015-03-12 07:30:00