Board index » cppbuilder » windows shutdown or restart

windows shutdown or restart


2004-01-23 07:07:21 PM
cppbuilder105
I need a very little program to shutdown or restart MS Window. Anybody can help ?
 
 

Re:windows shutdown or restart

"iims" < XXXX@XXXXX.COM >wrote in message
Quote

I need a very little program to shutdown or restart MS Window. Anybody can
help ?
bool Shutdown(bool RebootFlag = false)
{
//InitiateSystemShutdown
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
//-------------------
char *name=""; // address of name of computer to shut down
char *msg=""; //address of message to display in dialog box
DWORD time=0; // time to display dialog box
bool force=true; // force applications with unsaved changes flag
bool reboot=RebootFlag; //reboot flag
//---------------------------------------------------------------------
OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
&hToken);
if (!LookupPrivilegeValue(name,
SE_SHUTDOWN_NAME,
&tkp.Privileges[0].Luid)){
printf ("SE_SHUTDOWN_NAME Privilege ????? \n");
// return 1 ;
}
tkp.PrivilegeCount =1;
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,(PTOKEN_PRIVILEGES)NULL, 0);
if
(!LookupPrivilegeValue(name,SE_REMOTE_SHUTDOWN_NAME,&tkp.Privileges[0].Luid)
){
printf("SE_REMOTE_SHUTDOWN_NAME Privilege ????? \n");
// return 2 ;
}
tkp.PrivilegeCount =1;
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,(PTOKEN_PRIVILEGES)NULL, 0);
if (InitiateSystemShutdown(name,msg,time,force,reboot))
printf("%s shutdown Ok\n",name);
else {
printf("Can't shutdown %s \n",name);
return false;
}
return true;
}