https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=16760

David B. Trout <f...@infidels.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |f...@infidels.org
           Priority|Low                         |High

--- Comment #1 from David B. Trout <f...@infidels.org> ---
Copy of corrective code from bug description:


(Reference:
https://docs.microsoft.com/en-us/windows/win32/shutdown/how-to-shut-down-the-system)


#include <windows.h>

#pragma comment( lib, "user32.lib" )
#pragma comment( lib, "advapi32.lib" )

BOOL MyWindowsLogoff()
{
    HANDLE hToken;
    TOKEN_PRIVILEGES tkp;

    // Get a token for this process.

    if (!OpenProcessToken( GetCurrentProcess(),
        TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken ))
    {
        return FALSE;
    }

    // Get the LUID for the shutdown privilege.

    LookupPrivilegeValue( NULL, SE_SHUTDOWN_NAME,
        &tkp.Privileges[0].Luid );

    tkp.PrivilegeCount = 1;  // one privilege to set
    tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

    // Set the shutdown privilege for this process.

    AdjustTokenPrivileges( hToken, FALSE, &tkp, 0,
        (PTOKEN_PRIVILEGES) NULL, 0 );

    if (GetLastError() != ERROR_SUCCESS)
        return FALSE;

    // Logoff the user as requested.

    if (!ExitWindowsEx(
        0
            | EWX_LOGOFF
            | EWX_FORCEIFHUNG
        ,
        0
            | SHTDN_REASON_MAJOR_APPLICATION
            | SHTDN_REASON_MINOR_INSTALLATION
            | SHTDN_REASON_FLAG_PLANNED
    ))
        return FALSE;

    // Request successfully started

    return TRUE;
}

-- 
You are receiving this mail because:
You are watching all bug changes.
___________________________________________________________________________
Sent via:    Wireshark-bugs mailing list <wireshark-bugs@wireshark.org>
Archives:    https://www.wireshark.org/lists/wireshark-bugs
Unsubscribe: https://www.wireshark.org/mailman/options/wireshark-bugs
             mailto:wireshark-bugs-requ...@wireshark.org?subject=unsubscribe

Reply via email to