求助,一段代码在PB 12.0 和PB 6.5 下运行的问题
有一段在PB 6.5下的代码,运行正常。最近移植到PB 12.0 (评估版),发现有个api函数的运行结果总是失败,请大家帮忙找找原因。代码如下:
==================
= Windows 2000,XP 下的关机程序 =
==================
//=== 声明扩展函数 ====
FUNCTION ulong GetCurrentProcess() LIBRARY "kernel32.dll"
FUNCTION ulong OpenProcessToken(ulong ProcessHandle,ulong DesiredAccess,ref ulong TokenHandle) LIBRARY "advapi32.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 ExitWindowsEx(ulong uFlags,ulong dwReserved) LIBRARY "user32.dll"
//=== 关机代码 ======
string ls_lpSystemName
string ls_lpName = "SeShutdownPrivilege"
ulong lu_hdlProcessHandle
ulong lu_hdlTokenHandle
ulong 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) //**** 有问题的API函数 *******//
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)
//===============================
注:api函数LookupPrivilegeValue在PB 6.5下运行的结果总是1(成功),在PB 12.0下的运行结果总是0(失败),查了一些资料,但是还是找不到原因,请各位高手帮帮忙!