Q> Как зашутдаунить удаленный
компьютер?
A>
int main(int argc, char **argv)
{
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=true; //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 0;
}