Use the API to call Windows "LogoutRestartShock" function

zhaozj2021-02-08  208

Home: http://www.maxss.net email: maxchou@163.com

People who have used flashget should know that there is a function of shutting down the computer after a download completion in the flashget, how is this feature implementation? In fact, it can be done by calling a Windows API function exitWindowSex (). However, the Windows 98 and Windows 2000 implementation are slightly different, and will be described below.

EXITWINDOWSEX () function definition format:

Bool EXITWINDOWSEX

UINT UFLAGS, // Shutdown Operation

DWORD DWREASON // Shutdown Reason

For more detailed parameters, please refer to MSDN.

Remove the "Logout / Restart / Shock" function code in Windows 98:

EXITWINDOWSEX (EWX_LOGOFF, 0); // Logout

EXITWINDOWSEX (EWX_REBOOT, 0); // Restart

EXITWINDOWSEX (EWX_SHUTDOWN, 0); // Shutdown

Remove the "Logout / Restart / Shock" function code in Windows 2000:

Handle htokeen;

Token_Privileges TKP;

IF (fforce) // forces processes to Terminate

Fflag | = EWX_FORCE;

// Get Version Info to Dermine Operation

OsversionInfo Osvi;

Osvi.dwosversionInfosize = SizeOf (OsversionInfo);

IF (GetversionEx (& OSVI) == 0)

Return False;

// determine the Platform

IF (OSVI.DWPLATFORMID == Ver_Platform_Win32_NT)

{

// Windows NT 3.51, Windows NT 4.0, Windows 2000,

// Windows XP, or Windows .NET Server

IF (! openprocesstoken (getCurrentProcess (),

Token_adjust_privileges | token_query, & htokeen))

Return False;

Lookuppprivilegevalue (NULL, SE_SHUTDOWN_NAME, & TKP.PRIVILEGES [0] .luid);

Tkp.privilegect = 1; // one privilege to set

Tkp.privileges [0] .attributes = se_privilege_enabled;

AdjustTokenprivileges (HToken, False, & Tkp, 0, (ptoken_privileges) null, 0);

}

EXITWINDOWSEX (fflag, 0);

转载请注明原文地址:https://www.9cbs.com/read-2155.html

New Post(0)