02-07-2006 03:12 AM
02-07-2006 03:42 AM
02-07-2006 04:14 AM
On Windows/XP the Shudown command is available that permits to turn off or restart the computer: simply launch it with LaunchExecutable passing the appropriate command line options.
For a referenc on this command, simply open a command prompt, type SHUTDOWN and press Enter: all the available options will be listed on the screen.
02-07-2006 11:46 AM
below a function that shutdown computer using SDK
int Digital_StopComputer (void)
{
int error = 0;
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
// Get a token for this process.
if (!OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
{
error = -1;
errChk(error);
}
// 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;
// Get the shutdown privilege for this process.
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
(PTOKEN_PRIVILEGES)NULL, 0);
if (GetLastError() != ERROR_SUCCESS)
{
error = -1;
errChk(error);
}
//Reboot the system
if (!ExitWindowsEx(EWX_SHUTDOWN, 0))
{
error = -1;
errChk(error);
}
Error :
return error;
}