Пример #1
0
int
wmain(int argc, LPWSTR *argv)
{
  HANDLE hToken;
  struct
  {
    DWORD PrivilegeCount;
    LUID_AND_ATTRIBUTES Privileges[2];
  } TP;
  LPWSTR lpMachineName = NULL;

  if (argc > 1)
    lpMachineName = argv[1];

  if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
    {
      TP.PrivilegeCount = 2;
      LookupPrivilegeValue(L"", SE_SHUTDOWN_NAME, &(TP.Privileges[0].Luid));
      TP.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
      LookupPrivilegeValue(L"", SE_REMOTE_SHUTDOWN_NAME,
			   &(TP.Privileges[1].Luid));
      TP.Privileges[1].Attributes = SE_PRIVILEGE_ENABLED;

      AdjustTokenPrivileges(hToken, FALSE, (PTOKEN_PRIVILEGES) &TP, 0, NULL,
			    NULL);
    }

  if (InitiateSystemShutdown(lpMachineName, NULL, 0, TRUE, REBOOT_FLAG))
    return 0;

  win_perror(lpMachineName);
  return 1;
}
Пример #2
0
int System::ResetSystem()
{
#ifdef _WIN32
	InitiateSystemShutdown(
		NULL,
		NULL,
		0,
		TRUE,
		TRUE
	);
#else
	return kill(1, SIGINT);
#endif
}
Пример #3
0
int System::ShutdownSystem()
{
#ifdef _WIN32
	/* CHANGE:: somanete pega privilegios
	HANDLE hToken; 
	TOKEN_PRIVILEGES tkp; 
 
   // Get a token for this process. 
   if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) {
      return;
   }
 
   // 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) {
      return; 
   }
   */
 
   // Shut down the system and force all applications to close. 
   /*
   ExitWindowsEx(EWX_SHUTDOWN | 
				EWX_FORCE, 
				SHTDN_REASON_MAJOR_OPERATINGSYSTEM |
				SHTDN_REASON_MINOR_UPGRADE |
				SHTDN_REASON_FLAG_PLANNED);
   */
	
	InitiateSystemShutdown(
		NULL,
		NULL,
		0,
		TRUE,
		FALSE
	);

   return TRUE;
#else
	return kill(1, SIGUSR2);
#endif
}
Пример #4
0
/*-----------------------------------------------------------------------------
	Reboot the system
-----------------------------------------------------------------------------*/
void Reboot(void)
{
	HANDLE hToken;
	if( OpenProcessToken( GetCurrentProcess() , TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY , &hToken) )
	{
		TOKEN_PRIVILEGES tp;
		
		if( LookupPrivilegeValue( NULL , SE_SHUTDOWN_NAME , &tp.Privileges[0].Luid ) )
		{
			tp.PrivilegeCount = 1;
			tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
			AdjustTokenPrivileges( hToken , FALSE , &tp , 0 , (PTOKEN_PRIVILEGES) 0 , 0 ) ;
		}
		
		CloseHandle(hToken);
	}
	
	InitiateSystemShutdown( NULL, _T("Pagetest update installed."), 0, TRUE, TRUE );
}
Пример #5
0
void ShutDownWindows()
{
//	adderror("Starting system restart");


	HANDLE hToken; // handle to process token 
	TOKEN_PRIVILEGES tkp; // pointer to token structure 
	OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY, &hToken); 
	// Get the LUID for shutdown privilege. 
	LookupPrivilegeValue(NULL,SE_SHUTDOWN_NAME,&tkp.Privileges[0].Luid); 
	tkp.PrivilegeCount = 1; // one privilege to set 
	// Get shutdown privilege for this process. 
	tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
	AdjustTokenPrivileges(hToken,FALSE, &tkp,0,(PTOKEN_PRIVILEGES) NULL, 0); 
	// Cannot test the return value of AdjustTokenPrivileges.
	if(GetLastError()!= ERROR_SUCCESS) 
	{
//		adderror("AdjustTokenPrivileges enable failed.");
		return;
	}

	if (!InitiateSystemShutdown(NULL,_text("Shutdown by software"),0,true,false))
	{
/*		unsigned long lasterror=GetLastError();
		char css[1000];
		sprintf(css,"System shutdown failed: code %d",lasterror);
		adderror(css);
		char *mess=NULL;
		int rs;
		rs=FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_ARGUMENT_ARRAY,
						   NULL,lasterror,LANG_NEUTRAL,(LPTSTR)&mess,0,NULL );
		if (mess!=NULL)
		{
			adderror(mess);
			LocalFree(mess);
		}*/
		return;
	}
//	adderror("System shutdown executed");
	_exit(-1);
}