我在搜索选择文件夹对话时找到了此代码。我正在获取文件夹选择窗口,但我不知道为什么窗口在一次通话中被多次触发。
Function Select-FolderDialog
{
Param(
[string]$Description="Select Folder",
[string]$RootFolder="Desktop"
)
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null
$objForm = New-Object System.Windows.Forms.FolderBrowserDialog
$objForm.Rootfolder = $RootFolder
$objForm.Description = $Description
$Show = $objForm.ShowDialog()
If ($Show -eq "OK")
{
Return $objForm.SelectedPath
}
Else
{
Write-Error "Operation cancelled by user."
}
}