明輝手游網(wǎng)中心:是一個免費提供流行視頻軟件教程、在線學(xué)習(xí)分享的學(xué)習(xí)平臺!

用PB完成Windows2000下的自動關(guān)機

[摘要]在Windows2000中關(guān)機與在Windows98中不一樣,需要首先獲得權(quán)限,然后調(diào)用關(guān)機API函數(shù),才能關(guān)機。以下是具體的步驟:第一步: 聲明結(jié)構(gòu)-----------------------------------------------------------------------需要聲...
    在Windows2000中關(guān)機與在Windows98中不一樣,需要首先獲得權(quán)限,然后調(diào)用關(guān)機API函數(shù),才能關(guān)機。以下是具體的步驟:

第一步: 聲明結(jié)構(gòu)
-----------------------------------------------------------------------

需要聲明三個結(jié):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[]



第二步: 聲明外部擴展函數(shù)
-----------------------------------------------------------------------

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"



第三步: 程序腳本

-----------------------------------------------------------------------

/*獲得關(guān)機權(quán)限*/

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)


/*關(guān)機*/

ExitWindowsEx (9,0)


/* The End */

如果您在這篇文章里得到了些什么,請給作者一些鼓勵:zaodt_ms@hotmail.com