我看到了很多关于如何从映射的驱动器字母中获取UNC路径的问题,但是没有一个是相反的问题。
在不同的Windows7EnterpriseMachine上,对于具有完全相同的输入、当前目录和网络驱动器映射的FileName of System.Windows.Forms.OpenFileDialog实例,我得到了不同的答案:
我需要每台计算机用映射的驱动器路径回答:接收FileName的命令行程序不理解UNC路径。以下是sign-log.ps1的内容
Add-Type -AssemblyName System.Windows.Forms
function Sign-Log ($file = '.\check-log.xlsx') {
$FileBrowser = New-Object System.Windows.Forms.OpenFileDialog -Property @{
Title = 'Select'
; InitialDirectory = (Get-Location).Path
; Filename = 'check log.xlsx'
; Filter = 'Excel Spreadsheet (*.xlsx;*.xls)|*.xlsx;*.xls|Any file (*.*)|*.*'
; ShowHelp = $true
}
if ($FileBrowser.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK) {
$file = $FileBrowser.FileName
$dest = $file + '.sig'
if (Test-Path -Path $dest) {
Write-Verbose -Message ('Appending signature to {0}' -f $dest)
Add-Content -Path $dest -Value (gpg '-ao' '-' '-b' $file)
} else {
Write-Verbose -Message ('Writing signature to {0}' -f $dest)
gpg '-ao' $dest '-b' $file
}
gpg '--verify' $dest
}
$FileBrowser.Dispose()
}
Sign-Log我需要做什么来始终得到映射的驱动器路径?
发布于 2014-09-07 22:34:12
我认为最好的选择是测试是否返回UNC路径,如果是的话,将其临时映射到驱动器号,然后将其发送到gpg。也许是这样的:
if (([uri]$dest).IsUnc) {
$destPath = $dest | Split-Path -Parent
# Find a free drive letter
$letter = ls function:[d-z]: -n | ?{ !(test-path $_) } | Select-Object -Last 1
New-PSDrive -Name $letter[0] -Root $destPath -Persist -PSProvider FileSystem
$dest = $destPath | Join-Path -ChildPath $file
}
# Then after you're done calling gpg:
if ($destPath) {
Remove-PSDrive -Name $letter[0] -Force
}这是未经检验的..。
获得免费驾驶信的一条线来自于这里:得到一个免费的驱动器字母
新PSDrive参考
移除-PSDrive引用
https://stackoverflow.com/questions/25714865
复制相似问题