本文整理匯總了Java中com.sun.jna.platform.win32.Advapi32類的典型用法代碼示例。如果您正苦於以下問題:Java Advapi32類的具體用法?Java Advapi32怎麽用?Java Advapi32使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Advapi32類屬於com.sun.jna.platform.win32包,在下文中一共展示了Advapi32類的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: adjustPrivileges
import com.sun.jna.platform.win32.Advapi32; //導入依賴的package包/類
public static boolean adjustPrivileges() {
WinNT.TOKEN_PRIVILEGES tp = new WinNT.TOKEN_PRIVILEGES(1);
WinNT.TOKEN_PRIVILEGES oldtp = new WinNT.TOKEN_PRIVILEGES(1);
WinNT.LUID luid = new WinNT.LUID();
WinNT.HANDLEByReference hTokenRef = new WinNT.HANDLEByReference();
if (!Advapi32.INSTANCE.OpenProcessToken(Kernel32.INSTANCE.GetCurrentProcess(), WinNT.TOKEN_ADJUST_PRIVILEGES | WinNT.TOKEN_QUERY, hTokenRef)) {
return false;
}
WinNT.HANDLE hToken = hTokenRef.getValue();
if (!Advapi32.INSTANCE.LookupPrivilegeValue(null, WinNT.SE_DEBUG_NAME, luid)) {
Kernel32.INSTANCE.CloseHandle(hToken);
return false;
}
tp.PrivilegeCount = new WinDef.DWORD(1);
tp.Privileges = new WinNT.LUID_AND_ATTRIBUTES[1];
tp.Privileges[0] = new WinNT.LUID_AND_ATTRIBUTES(luid, new WinDef.DWORD(WinNT.SE_PRIVILEGE_ENABLED));
IntByReference retSize = new IntByReference(0);
if (!Advapi32.INSTANCE.AdjustTokenPrivileges(hToken, false, tp, tp.size(), oldtp, retSize)) {
Kernel32.INSTANCE.CloseHandle(hToken);
return false;
}
Kernel32.INSTANCE.CloseHandle(hToken);
privAdjusted = true;
return true;
}