本文整理汇总了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;
}