简体   繁体   中英

GetForegroundWindow throws Win32Exception Access Denied

public partial class Form1 : Form
{
    [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
    private static extern IntPtr GetForegroundWindow();

    public Form1()
    {
        InitializeComponent();
        var proc = Process.GetProcesses().Single(x => x.Handle == GetForegroundWindow());
    }
}

I've tried running the app as Administrator, no go. What am I doing wrong here that I get this exception?

原来,我正在执行的整个循环也正在遍历受保护的进程,这导致访问被拒绝

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM