In Windows 2000, the gate is different from Windows 98, you need to get permissions first, then call the shutdown API function to shut down. The following is a specific step:
Step 1: Declaration structure ---------------------------------------------------------------------------------------------------------------------------------------------------------------- ---------------------------
Need to declare three knots: Luid, Luid_and_attributes, Token_Privileges
LUID
Long LowPart Long Highpart
Luid_and_attributes
Luid Pluid Long Attributes
Token_Privileges
Long privilegect luid_and_attributes privileges []
Step 2: Declare the external expansion function ------------------------------------------------------------------------------------------------------------------ -----------------------------
FUNCTION ulong ExitWindowsEx (ulong uFlags, ulong dwReserved) LIBRARY "user32.dll" FUNCTION ulong GetCurrentProcess () LIBRARY "kernel32.dll" FUNCTION ulong LookupPrivilegeValue (ref string lpSystemName, ref string lpName, ref Luid lpLuid) LIBRARY "advapi32.dll" ALIAS FOR "LookupPrivilegeValueA" FUNCTION ulong AdjustTokenPrivileges (ulong TokenHandle, boolean DisableAllPrivileges, ref TOKEN_PRIVILEGES NewState, ulong BufferLength, ref TOKEN_PRIVILEGES PreviousState, ref ulong ReturnLength) LIBRARY "advapi32.dll" FUNCTION ulong OpenProcessToken (ulong ProcessHandle, ulong DesiredAccess, ref ulong TokenHandle) LIBRARY "advapi32.dll"
Step 3: Program script
-------------------------------------------------- ---------------------
/ * Get shutdown rights * /
string ls_lpSystemName, ls_lpNamels_lpname = 'SeShutdownPrivilege'ulong lu_hdlProcessHandle, lu_hdlTokenHandle, lu_lBufferNeededluid lst_tmpLuidTOKEN_PRIVILEGES lst_tkpTOKEN_PRIVILEGES lst_tkpNewButIgnoredlu_hdlProcessHandle = GetCurrentProcess () OpenProcessToken (lu_hdlProcessHandle, 40, lu_hdlTokenHandle) LookupPrivilegeValue (ls_lpSystemName, ls_lpname, lst_tmpLuid) lst_tkp.PrivilegeCount = 1lst_tkp.Privileges [1] .pLuid = LST_TMPLUIDLST_TKP.PRIVILEGES [1] .attributes = 2 AdjustTokenPrivileges (Lu_HDLTOKENHHANDE, FALSE, LST_TKP, 16, LST_TKPNEWBUTINORED, LU_LBUFFERNEDED) / * Shutdown * /
EXITWINDOWSEX (9, 0)
/ * The end * /
If you have got some in this article, please give the author some encouragement: zaodt_ms@hotmail.com