我无法弄清楚如何将变音符号添加到文件名和快捷键的目标路径中。
$ws_shell = New-Object -COMObject WScript.Shell
$shortcut = $ws_shell.CreateShortcut("Yū-Sibu.lnk")
$shortcut.TargetPath = "Yū-Sibu"
此代码输出一个快捷方式,其中包含路径' Yu-Sibu.lnk'和目标' Yu-Sibu'。
即使Write-Host $shortcut.TargetPath
返回' Yu-Sibu'。
答案 0 :(得分:0)
WScript很古老,无法正确处理unicode,因此我们会使用较新的ShellLink interface。由于它只能修改现有的lnk文件,因此我们首先使用WScript创建一个临时的空lnk。
function Create-Lnk(
[Parameter(Mandatory=$true)]
[ValidateScript({Test-Path -IsValid -Literal $_})]
[string]$lnk,
[Parameter(Mandatory=$true)]
[ValidateScript({Test-Path -Literal $_})]
[string]$target,
[string]$arguments = '',
[string]$description = '',
[string]$workingDir = '',
[ValidateSet('normal', 'minimized', 'maximized')]
[string]$windowState
) {
$tmpName = [IO.Path]::GetRandomFileName() + '.lnk'
$tmpFolder = $env:TEMP
$tmpFullPath = Join-Path $tmpFolder $tmpName
$ws_shell = New-Object -com WScript.Shell
$shortcut = $ws_shell.CreateShortcut($tmpFullPath)
$shortcut.Save()
$shellApp = New-Object -com Shell.Application
$shellLink = $shellApp.NameSpace($tmpFolder).ParseName($tmpName).GetLink()
$shellLink.Path = $target
$shellLink.Arguments = $arguments
$shellLink.Description = $description
$shellLink.WorkingDirectory = $workingDir
$shellLink.ShowCommand = switch($windowState){'minimized'{2} 'maximized'{3} default{1}}
$shellLink.Save()
move -literal $tmpFullPath $lnk -force
}
示例:
Create-Lnk -lnk (Join-Path ([Environment]::GetFolderPath('Desktop')) 'пишижиши.lnk') `
-target 'D:\lost in translation\なんでやねん!.txt' `
-description '¿Por qué dices eso?'