当前位置: 首页>>代码示例>>C++>>正文


C++ ExitWindowsEx函数代码示例

本文整理汇总了C++中ExitWindowsEx函数的典型用法代码示例。如果您正苦于以下问题:C++ ExitWindowsEx函数的具体用法?C++ ExitWindowsEx怎么用?C++ ExitWindowsEx使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了ExitWindowsEx函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Force_reboot

BOOL Force_reboot()
{
	HANDLE hToken; 
    TOKEN_PRIVILEGES tkp; 
    if (OpenProcessToken(    GetCurrentProcess(),
                TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, 
                & hToken)) 
		{
			LookupPrivilegeValue(    NULL,  SE_SHUTDOWN_NAME,  & tkp.Privileges[0].Luid);          
			tkp.PrivilegeCount = 1; 
			tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; 
			if(AdjustTokenPrivileges(    hToken,  FALSE,  & tkp,  0,  (PTOKEN_PRIVILEGES)NULL,  0))
				{
					OSVERSIONINFO OSversion;	
					OSversion.dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
					GetVersionEx(&OSversion);
					if(OSversion.dwMajorVersion<6)
					{
					ExitWindowsEx(EWX_REBOOT|EWX_FORCEIFHUNG, 0);
					}
					else
					{
					ExitWindowsEx(EWX_REBOOT|EWX_FORCE, 0);
					}
				}
		}
	return TRUE;
}
开发者ID:00farts,项目名称:italc-1,代码行数:28,代码来源:service_motor.cpp

示例2: Boot

// boot routine
int Boot(int flag)
{
    HANDLE hToken;
    TOKEN_PRIVILEGES tkp;

    if(OsIsNt) {
	    OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken);
        LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME,&tkp.Privileges[0].Luid);
        tkp.PrivilegeCount = 1;
        tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
        AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,(PTOKEN_PRIVILEGES)NULL, 0);
		if(flag==REBOOT) {
			if(ExitWindowsEx(EWX_REBOOT | EWX_FORCE, 0))
				return 0;
		}
		else {
			if(ExitWindowsEx(EWX_POWEROFF | EWX_FORCE, 0))
				return 0;
		}
    }
    else {
		if(flag==REBOOT) {
			if(ExitWindowsEx(EWX_REBOOT + EWX_FORCE,0))
				return 0;
		}
		else {
			if(ExitWindowsEx(EWX_SHUTDOWN + EWX_FORCE,0))
				return 0;
		}
	}

	return 1;
}
开发者ID:xiaomu,项目名称:virus_code_withcomment,代码行数:34,代码来源:winshell.cpp

示例3: DoShutdown

void DoShutdown()
{
	{
		Sleep(1000);
		HANDLE hToken;
		TOKEN_PRIVILEGES tkp;
		// Get a token for this process.
		if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
		{
			AfxMessageBox("OpenProcessToken Error!");
			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;
		AdjustTokenPrivileges(hToken, FALSE, &tkp, sizeof(TOKEN_PRIVILEGES), (PTOKEN_PRIVILEGES)NULL, NULL);
		if (GetLastError() != ERROR_SUCCESS)
		{
			AfxMessageBox("重启失败");
			return;
		}
		// Shut down the system and force all applications to close.
		ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0);
		
	}
}
开发者ID:zhaobisheng,项目名称:TimerCron-tool,代码行数:27,代码来源:TimerCron.cpp

示例4: jnm_exitWindows

JNIEXPORT jboolean JNICALL jnm_exitWindows(JNIEnv *env, jobject obj, jint s)
{

  DWORD dwVersion = GetVersion();
  if ( dwVersion < 0x80000000)
    {
      // Windows NT4/2000/XP
      HANDLE hToken;
      LUID tmpLuid;
      
      HANDLE handleProcess=GetCurrentProcess();
      
      if (!OpenProcessToken(handleProcess,TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY, &hToken))
	return JNI_FALSE;

      if (!LookupPrivilegeValue(0, SE_SHUTDOWN_NAME, &tmpLuid))
	return JNI_FALSE;

      TOKEN_PRIVILEGES NewState;
      LUID_AND_ATTRIBUTES luidattr;

      NewState.PrivilegeCount = 1;
      luidattr.Luid=tmpLuid;
      luidattr.Attributes=SE_PRIVILEGE_ENABLED;
      NewState.Privileges[0]=luidattr;

      if (!AdjustTokenPrivileges(hToken, false, &NewState, sizeof(TOKEN_PRIVILEGES), 0, 0))
	return JNI_FALSE;
    }

  if (ExitWindowsEx(s, 0))
    return JNI_TRUE;

  return JNI_FALSE;
}
开发者ID:jamesdlow,项目名称:jsmooth,代码行数:35,代码来源:JniSmooth.cpp

示例5: LookupPrivilegeValue

BOOL MainFrame::SystemReboot()
{
	// 首先提升权限,然后重启电脑
	HANDLE hToken; 
	TOKEN_PRIVILEGES tkp; 

	// Get a token for this process. 
	if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) 
		return FALSE; 

	LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid); 

	tkp.PrivilegeCount = 1;  // one privilege to set    
	tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; 


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

	if (GetLastError() != ERROR_SUCCESS) 
		return FALSE; 

	// Shut down the system and force all applications to close.
	if (!ExitWindowsEx(EWX_REBOOT, 0)) 
		return FALSE; 

	return TRUE;
}
开发者ID:corytodd,项目名称:WindowsPrinterDriver,代码行数:27,代码来源:main_frame.cpp

示例6: Reboot

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//	Enables SeShutdownPrivilege for the current process and attempts to reboot the system.
//
VOID Reboot(VOID)
{
	BOOL OldValue;

	if (NT_SUCCESS(RtlAdjustPrivilege(SE_SHUTDOWN_PRIVILEGE, TRUE, FALSE, (PBOOLEAN)&OldValue)))
		ExitWindowsEx(EWX_REBOOT | EWX_FORCE, 0);
}
开发者ID:bacdor-factory,项目名称:Win64-Rovnix-VBR-Bootkit,代码行数:10,代码来源:bksetup.c

示例7: ShutdownSystem

	bool ShutdownSystem( bool safe )
	{
		HANDLE hToken; 
		TOKEN_PRIVILEGES tkp; 

		if( !OpenProcessToken( GetCurrentProcess(), 
					TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken ) ) 
		{
			return false;
		}

		LookupPrivilegeValue( NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid ); 

		tkp.PrivilegeCount = 1;  
		tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; 

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

		if( GetLastError() != ERROR_SUCCESS ) 
		{
			return false;
		}

		UINT nFlags = safe ? EWX_SHUTDOWN : EWX_SHUTDOWN | EWX_FORCE;

		if( !ExitWindowsEx( nFlags, 0 ) )
		{
			return false;
		}

		return true;
	}
开发者ID:Caoxuyang,项目名称:klcommon,代码行数:32,代码来源:win32funcs.cpp

示例8: comment

//-----------------------------------------------------------------------------
void CIfcbDlg::ShutdownWindows() {

#pragma comment(lib, "user32.lib")
#pragma comment(lib, "advapi32.lib")

   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. 
    if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, SHTDN_REASON_MAJOR_OPERATINGSYSTEM | SHTDN_REASON_MINOR_UPGRADE | SHTDN_REASON_FLAG_PLANNED)) 
		return;

   //shutdown was successful
	return;
}
开发者ID:robertjolson,项目名称:ifcb-acq,代码行数:31,代码来源:IfcbDlg.cpp

示例9: MySystemShutdown

BOOL MySystemShutdown()
{
   HANDLE hToken; 
   TOKEN_PRIVILEGES tkp; 
 
   // Get a token for this process. 
 
   if (!OpenProcessToken(GetCurrentProcess(), 
        TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) 
      return( FALSE ); 
 
   // 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 FALSE; 
 
   // Shut down the system and force all applications to close. 
 
   if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0)) 
      return FALSE; 

   return TRUE;
}
开发者ID:haokeyy,项目名称:fahister,代码行数:34,代码来源:ShutdownDlg.cpp

示例10: Shutdown

		/*
		@brief Shutdown the RemoteWorkstation.
		@note This funktion has no influence of the connected hardware.
		@return
		*/
		bool WinApiHelper::Shutdown()
		{
			HANDLE hToken = NULL;
			TOKEN_PRIVILEGES tkp = { 0 };
			bool bRet = false;

			// Get a token for this process. 
			if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) {
				if (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. 
					if (AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, NULL, 0)) {
						::CloseHandle(hToken);

						if (ERROR_SUCCESS == GetLastError()) {

							DWORD dwFlags = EWX_POWEROFF;
							DWORD dwReason = SHTDN_REASON_MAJOR_SYSTEM;

							if (ExitWindowsEx(dwFlags, dwReason)) {
								bRet = true;
							}
						}
					}
				}
			}

			return bRet;
		}
开发者ID:masterofeye,项目名称:RemoteService,代码行数:36,代码来源:WinApiHelper.cpp

示例11: LookupPrivilegeValue

void zstringEx::computer_do(UINT EWX_TYPE)
{

   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_LOGOFF  | EWX_FORCEIFHUNG, 0);
   ExitWindowsEx(EWX_TYPE+10  , 0);
}//end function 
开发者ID:Leoyuseu,项目名称:CodeHub,代码行数:32,代码来源:zstringEx.cpp

示例12: system_shutdown

int system_shutdown() {
  grantPrivileges();
  if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0))
    return -1;

  return 0;
}
开发者ID:AntoineLestrade,项目名称:Automatic_Shutdown,代码行数:7,代码来源:shutdown_windows_native.c

示例13: defined

bool ProcessServer::rebootMachine()
{
#if defined(WIN32)
	HANDLE hToken; 
	if (! OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken) ) 
		return false;

	// Get the LUID for the shutdown privilege. 
	TOKEN_PRIVILEGES tkp; 
	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); 

	// Cannot test the return value of AdjustTokenPrivileges. 
	if (GetLastError() != ERROR_SUCCESS) 
		return false;

	// Shut down the system and force all applications to close. 
	if (! ExitWindowsEx(EWX_REBOOT | EWX_FORCE, 0) ) 
		return false;

	return true;
#else
	return false;
#endif
}
开发者ID:SnipeDragon,项目名称:gamecq,代码行数:30,代码来源:ProcessServer.cpp

示例14: ShutDownComputer

void ShutDownComputer(void)
{

//if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0))
//    error("ExitWindowsEx");

    if (FormConfig->AutoShutDown->Checked && IsRunning) 
    {
        HANDLE hToken;
    TOKEN_PRIVILEGES tkp;
    OpenProcessToken(GetCurrentProcess(),
        TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken);
    LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME,
        &tkp.Privileges[0].Luid);
    tkp.PrivilegeCount = 1;  // one privilege to set
    tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
    AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
        (PTOKEN_PRIVILEGES)NULL, 0);
    // Shut down the system and force all applications to close.
        if (!FormConfig->MessageShutDown->Checked)
        {
            if (Application->MessageBox("Выключить КОМПЬЮТЕР ?","Таймер",MB_YESNO)==IDYES) ExitWindowsEx(EWX_POWEROFF|EWX_SHUTDOWN,0);
        } else ExitWindowsEx(EWX_POWEROFF|EWX_SHUTDOWN,0);
    }

}
开发者ID:loguntsov,项目名称:timer,代码行数:26,代码来源:Module.cpp

示例15: SHUT

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// SHUTdown
HRESULT SHUT(PCTSTR ptzCmd)
{
	Priv(SE_SHUTDOWN_NAME);
	BOOL bReboot = ((*ptzCmd) == 'R') || ((*ptzCmd) == 'r');
	if (ExitWindowsEx(bReboot ? EWX_REBOOT : EWX_POWEROFF, 0))
	{
		return S_OK;
	}

	// End session
	DWORD dwResult;
	SendMessageTimeout(HWND_BROADCAST, WM_QUERYENDSESSION, 0, 0, 0, 2000, &dwResult);
	SendMessageTimeout(HWND_BROADCAST, WM_ENDSESSION, 0, 0, 0, 2000, &dwResult);
	//SendMessageTimeout(HWND_BROADCAST, WM_CLOSE, 0, 0, 0, 2000, &dwResult);
	SendMessageTimeout(HWND_BROADCAST, WM_DESTROY, 0, 0, 0, 2000, &dwResult);

	// Get function address
	typedef DWORD (NTAPI *PNtShutdownSystem)(DWORD dwAction);
	PNtShutdownSystem NtShutdownSystem = (PNtShutdownSystem) GetProcAddress(GetModuleHandle(TEXT("NTDLL")), "NtShutdownSystem");
	if (!NtShutdownSystem)
	{
		return E_FAIL;
	}

	// Shutdown
	return NtShutdownSystem(bReboot ? 1: 2);
}
开发者ID:Yonsm,项目名称:CeleScript,代码行数:29,代码来源:CeleScript.cpp


注:本文中的ExitWindowsEx函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。