简体   繁体   English

OpenProcess 失败(SeDebugPrivilege?)

[英]OpenProcess Failure (SeDebugPrivilege?)

I'm trying to use OpenProcess, for some reason it keeps failing.我正在尝试使用 OpenProcess,但由于某种原因它一直失败。

HANDLE GetProcessPid()
{
    DWORD pid = 0;
    wchar_t ProcessName[] = L"notepad.exe";

    // Create toolhelp snapshot.
    HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
    PROCESSENTRY32 process;
    ZeroMemory(&process, sizeof(process));
    process.dwSize = sizeof(process);

    // Walkthrough all processes.
    if (Process32First(snapshot, &process))
    {
        do
        {
            if (wcscmp(process.szExeFile, ProcessName) == 0)
            {
                pid = process.th32ProcessID;
                break;
            }
        } while (Process32Next(snapshot, &process));
    }

    CloseHandle(snapshot);

    if (pid != 0)
    {
        return OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
    }

    return NULL;
}

This always returns 0xcccccccccccccccc or 0x0000000000000020 even when I've set the pid manually when calling OpenProcess.即使我在调用 OpenProcess 时手动设置了 pid,这也总是返回 0xcccccccccccccccc 或 0x0000000000000020。

I've tried running as admin outside of debugging inside visual studio and get the same results, after searching, I think I need to enable debug priviledges (SeDebugPrivilege), how do I do this in visual studio 2013?我已经尝试在 Visual Studio 内部调试之外以管理员身份运行并获得相同的结果,搜索后,我想我需要启用调试权限 (SeDebugPrivilege),我该如何在 Visual Studio 2013 中执行此操作?

你的代码很好,你只需要以管理员身份运行你的可执行文件就可以了,我刚刚测试了它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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