cet*_*int 82 powershell command-line shortcut desktop-shortcut
我想用PowerShell为这个可执行文件创建一个快捷方式:
C:\Program Files (x86)\ColorPix\ColorPix.exe
Run Code Online (Sandbox Code Playgroud)
如何才能做到这一点?
CB.*_*CB. 122
我不知道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()
Run Code Online (Sandbox Code Playgroud)
您可以在$ 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()
Run Code Online (Sandbox Code Playgroud)
并称之为这样
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"
Run Code Online (Sandbox Code Playgroud)
在 $ 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()
Run Code Online (Sandbox Code Playgroud)
JPB*_*anc 37
开始的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"
Run Code Online (Sandbox Code Playgroud)
要小心,SymbolicLink与快捷方式不同,快捷方式只是一个文件.它们有一个大小(一个小的,只引用它们指向的位置),并且它们需要一个应用程序来支持该文件类型才能使用.符号链接是文件系统级别,所有内容都将其视为原始文件.应用程序不需要特殊支持即可使用符号链接.
无论如何,如果您想使用Powershell 创建一个Run As Administrator快捷方式,您可以使用
$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)
Run Code Online (Sandbox Code Playgroud)
如果有人想要更改.LNK文件中的其他内容,您可以参考Microsoft官方文档.
归档时间: |
|
查看次数: |
134609 次 |
最近记录: |