在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 desiredaccess,ref ulong tokenhandle) library “advapi32.dll”
第三步: 程序脚本
———————————————————————–
/*获得关机权限*/
string ls_lpsystemname,ls_lpname
ls_lpname=seshutdownprivilege
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
功能: 强行关闭所有程式并关机。