Windows PowerShellでのMicrosoft.Win32.OpenFileDialog.ShowDialog
とSystem.Windows.Forms.OpenFileDialog.ShowDialog
がウイルス対策ソフトでブロックされる。
Add-Type -AssemblyName PresentationFramework
$dlg = [Microsoft.Win32.OpenFileDialog]::new()
$dlg.ShowDialog()
Add-Type -AssemblyName System.Windows.Forms
$dlg = [System.Windows.Forms.OpenFileDialog]::new()
$dlg.ShowDialog()
ウイルス対策ソフトで今のところ、フォームへのドラッグ&ドロップはブロックされない様子。
Set-StrictMode -Version Latest
Add-Type -AssemblyName PresentationFramework
$paths = [System.Collections.Specialized.StringCollection]::new()
$w = New-Object -TypeName System.Windows.Window -Property @{
Title = "ドラッグ&ドロップ"
Width = 300
Height = 200
AllowDrop = $true
}
$w.add_Drop([System.Windows.DragEventHandler]{
param([object]$sender, [System.Windows.DragEventArgs]$e)
$paths = $e.Data.GetFileDropList()
$paths | Write-Host -ForegroundColor Cyan
$global:paths.AddRange($paths)
})
$w.ShowDialog()
$paths
Set-StrictMode -Version Latest
Add-Type -AssemblyName System.Windows.Forms
$paths = [System.Collections.Specialized.StringCollection]::new()
$f = New-Object -TypeName System.Windows.Forms.Form -Property @{
Text = "ドラッグ&ドロップ"
Width = 300
Height = 200
AllowDrop = $true
}
$f.add_DragEnter([System.Windows.Forms.DragEventHandler]{
param([object]$sender, [System.Windows.Forms.DragEventArgs]$e)
$e.Effect = [System.Windows.Forms.DragDropEffects]::All
})
$f.add_DragDrop([System.Windows.Forms.DragEventHandler]{
param([object]$sender, [System.Windows.Forms.DragEventArgs]$e)
$paths = $e.Data.GetFileDropList()
$paths | Write-Host -ForegroundColor Cyan
$global:paths.AddRange($paths)
})
$f.ShowDialog()
$paths