Skip to main content
gamedev.net
🔒 Locked

Shutdown Dialog

Started by Ratterbox 5 replies 900+ views
Original Post
Ratterbox
Ratterbox
Is there a function you can call to display the Shutdown / Turn off your computer dialog. I am make a mouse gesture program, and would like this to be one of the effects. Please let me know if this can or cannot be done. Many thanks. ---------------------- Ratterbox Neon Light Team | The Legion Team
daerid
daerid
I''m sure it can. Just a matter of finding the right API Function.


daerid | Legends | Garage Games | Spirit | Hapy | Boost | Python | Google
"Doomed to crumble, unless we grow, and strengthen our communication" - Maynard James Keenan, Tool
daerid@gmail.com
felisandria
felisandria
This is how. You might want to adjust the settings as I have it in irreversible, don''t even save what you''re working on, shut down whether you like it or not mode. Don''t ask.


HANDLE hToken; // handle to process token
TOKEN_PRIVILEGES tkp; // pointer to token structure

// Get the current process token handle so we can get shutdown
// privilege.

if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
{
// non gracefull kill with pwr
return;
}

// Get the LUID for 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;

// Get shutdown privilege for this process.

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

// Cannot test the return value of AdjustTokenPrivileges.

if (GetLastError() != ERROR_SUCCESS)
{
// non gracefull kill with pwr
return;
}

// Do immediate shutdown.
InitiateSystemShutdown( NULL, // shut down local computer
NULL, // message for user
10, // time-out period
TRUE, // force shutdown and ignore saves
FALSE); // reboot after shutdown

// Disable shutdown privilege.


tkp.Privileges[0].Attributes = 0;
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES) NULL, 0);
~ The opinions stated by this individual are the opinions of this individual and not the opinions of her company, any organization she might be part of, her parrot, or anyone else. ~

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.