Powershell - 当 运行 作为管理员时拖放不起作用

Powershell - Drag and Drop does not work when running as administrator

以下代码在我以管理员身份 运行 时不起作用。我拖放到GUI上的文件没有显示出来。

如果我 运行 脚本不是作为管理员工作。 :/

谁能告诉我为什么?

提前感谢您的帮助!

Function DragDropSample() {
    [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
    $form = New-Object Windows.Forms.Form
    $form.text = "Drag&Drop sample"
    $listBox = New-Object Windows.Forms.ListBox
    $listBox.Dock = [System.Windows.Forms.DockStyle]::Fill
    $handler = {
        if ($_.Data.GetDataPresent([Windows.Forms.DataFormats]::FileDrop)) {
            foreach ($filename in $_.Data.GetData([Windows.Forms.DataFormats]::FileDrop)) {
                $listBox.Items.Add($filename)
            }
        }
    }
    $form.AllowDrop = $true
    $form.Add_DragEnter($handler)
    $form.Controls.Add($listBox)
    $form.ShowDialog()
}

DragDropSample | Out-Null

这是 Windows 中用户帐户控制 (UAC) 的结果。您可以在任何应用程序中看到相同的行为。

比如正常打开记事本。将一个文本文件拖到上面。它打开了。

以管理员身份打开记事本,尝试拖一个文件。不行。

你应该可以在 2 个程序之间拖动 运行 提升,但据我所知,资源管理器永远不会运行提升,即使你明确告诉它,所以你必须从一些用作拖动源的其他应用程序。