怎样实现win2000自动关机(转贴)
发表于:2007-07-02来源:作者:点击数:
标签:
在Windows2000中关机与在Windows98中不一样,需要首先获得权限,然后调用关机API函数,才能关机。以下是具体的步骤: 第一步: 声明结构 ----------------------------------------------------------------------- 需要声明三个结:LUID, LUID_AND_ATTRIBUT
在Windows2000中关机与在Windows98中不一样,需要首先获得权限,然后调用关机API函数,才能关机。以下是具体的步骤:
第一步: 声明结构
-----------------------------------------------------------------------
需要声明三个结:LUID, LUID_AND_ATTRIBUTES, token_privileges
LUID
long lowpart
long highpart
LUID_AND_ATTRIBUTES
luid pLuid
long Attributes
token_privileges
long privilegecount
luid_and_attributes privileges[]
第二步: 声明外部扩展函数
-----------------------------------------------------------------------
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 DesiredA
clearcase/" target="_blank" >ccess,ref ulong TokenHandle) LIBRARY "advapi32.dll"
第三步: 程序脚本
-----------------------------------------------------------------------
/*获得关机权限*/
string ls_lpSystemName,ls_lpName
ls_lpname=@#SeShu
tdownPrivilege@#
ulong lu_hdlProcessHandle,lu_hdlTokenHandle,lu_lBufferNeeded
luid lst_tmpLuid
TOKEN_PRIVILEGES lst_tkp
TOKEN_PRIVILEGES lst_tkpNewButIgnored
lu_hdlProcessHandle = GetCurrentProcess()
OpenProcessToken(lu_hdlProcessHandle,40, lu_hdlTokenHandle)
LookupPrivilegeValue( ls_lpSystemName, ls_lpname, lst_tmpLuid)
lst_tkp.PrivilegeCount = 1
lst_tkp.Privileges[1].pLuid = lst_tmpLuid
lst_tkp.Privileges[1].Attributes = 2
AdjustTokenPrivileges(lu_hdlTokenHandle, False, lst_tkp,16, lst_tkpNewButIgnored,lu_lBufferNeeded)
/*关机*/
ExitWindowsEx (9,0)
/* The End */
///方法2
教你用个shell命令
rundll32.exe user.exe ,exitwindows
功能: 强行关闭所有程式并关机。
原文转自:http://www.ltesting.net