用PB+WIN2K实现ExitWindowsEx的, 请进来接分.
模拟MSDN自带的例子,写了一小段关机的代码, 但GetCurrentProcess()总是返回-1, GetLastError()显示拒绝访问.
网上搜了一圈, 代码内容大同小异, 百思不得其解, 那些把代码抄来抄去发表的人, 真得测试过么? 代码如下:
long hdlProcessHandle
long hdlTokenHandle
long lBufferNeeded
luid tmpLuid
TOKEN_PRIVILEGES tkp
TOKEN_PRIVILEGES tkpNewButIgnored
constant long SE_PRIVILEGE_ENABLED = 2
Constant long TOKEN_ADJUST_PRIVILEGES GetC = 32
Constant long TOKEN_QUERY = 8
inv_errsrv.SetLastError(0)
hdlProcessHandle = GetCurrentProcess()
MessageBox("GetCurrentProcess " + string(hdlProcessHandle), inv_errsrv.of_GetLastError(inv_errsrv.GetLastError()))
OpenProcessToken (hdlProcessHandle, 40, hdlTokenHandle)
MessageBox("OpenProcessToken", inv_errsrv.of_GetLastError(inv_errsrv.GetLastError()))
LookupPrivilegeValue ("", "SeShutdownPrivilege", tmpLuid)
MessageBox("LookupPrivilegeValue", inv_errsrv.of_GetLastError(inv_errsrv.GetLastError()))
tkp.PrivilegeCount = 1 // One privilege to set
tkp.TheLuid = tmpLuid
tkp.Attributes = SE_PRIVILEGE_ENABLED
AdjustTokenPrivileges (hdlTokenHandle, 0, tkp, 16, tkpNewButIgnored, lBufferNeeded)
MessageBox("AdjustTokenPrivileges", inv_errsrv.of_GetLastError(inv_errsrv.GetLastError()))
ExitWindowsEx (EWX_SHUTDOWN, 0)