use of com.sun.jna.platform.win32.Kernel32 in project jna by java-native-access.
the class Advapi32Test method testLookupAccountName.
public void testLookupAccountName() {
IntByReference pSid = new IntByReference(0);
IntByReference pDomain = new IntByReference(0);
PointerByReference peUse = new PointerByReference();
String accountName = "Administrator";
assertFalse(Advapi32.INSTANCE.LookupAccountName(null, accountName, null, pSid, null, pDomain, peUse));
assertEquals(W32Errors.ERROR_INSUFFICIENT_BUFFER, Kernel32.INSTANCE.GetLastError());
assertTrue(pSid.getValue() > 0);
Memory sidMemory = new Memory(pSid.getValue());
PSID pSidMemory = new PSID(sidMemory);
char[] referencedDomainName = new char[pDomain.getValue() + 1];
assertTrue(Advapi32.INSTANCE.LookupAccountName(null, accountName, pSidMemory, pSid, referencedDomainName, pDomain, peUse));
assertEquals(SID_NAME_USE.SidTypeUser, peUse.getPointer().getInt(0));
assertTrue(Native.toString(referencedDomainName).length() > 0);
}
use of com.sun.jna.platform.win32.Kernel32 in project jna by java-native-access.
the class Advapi32Test method testCloseServiceHandle.
public void testCloseServiceHandle() throws Exception {
SC_HANDLE handle = Advapi32.INSTANCE.OpenSCManager(null, null, Winsvc.SC_MANAGER_CONNECT);
assertNotNull(handle);
assertTrue(Advapi32.INSTANCE.CloseServiceHandle(handle));
assertFalse(Advapi32.INSTANCE.CloseServiceHandle(null));
assertEquals(W32Errors.ERROR_INVALID_HANDLE, Kernel32.INSTANCE.GetLastError());
}
use of com.sun.jna.platform.win32.Kernel32 in project jna by java-native-access.
the class Advapi32Test method testDuplicateTokenEx.
public void testDuplicateTokenEx() {
HANDLEByReference hExistingToken = new HANDLEByReference();
HANDLEByReference phNewToken = new HANDLEByReference();
try {
HANDLE processHandle = Kernel32.INSTANCE.GetCurrentProcess();
assertTrue(Advapi32.INSTANCE.OpenProcessToken(processHandle, WinNT.TOKEN_DUPLICATE | WinNT.TOKEN_QUERY, hExistingToken));
assertTrue(Advapi32.INSTANCE.DuplicateTokenEx(hExistingToken.getValue(), WinNT.GENERIC_READ, null, SECURITY_IMPERSONATION_LEVEL.SecurityAnonymous, TOKEN_TYPE.TokenPrimary, phNewToken));
} finally {
Kernel32Util.closeHandleRefs(phNewToken, hExistingToken);
}
}
use of com.sun.jna.platform.win32.Kernel32 in project jna by java-native-access.
the class ITypeLibTest method loadShellTypeLib.
private ITypeLib loadShellTypeLib() {
CLSID.ByReference clsid = new CLSID.ByReference();
// get CLSID from string
HRESULT hr = Ole32.INSTANCE.CLSIDFromString(new WString(SHELL_CLSID), clsid);
assertTrue(COMUtils.SUCCEEDED(hr));
// get user default lcid
LCID lcid = Kernel32.INSTANCE.GetUserDefaultLCID();
PointerByReference pShellTypeLib = new PointerByReference();
// load typelib
hr = OleAuto.INSTANCE.LoadRegTypeLib(clsid, SHELL_MAJOR, SHELL_MINOR, lcid, pShellTypeLib);
assertTrue(COMUtils.SUCCEEDED(hr));
return new TypeLib(pShellTypeLib.getValue());
}
use of com.sun.jna.platform.win32.Kernel32 in project jna by java-native-access.
the class Advapi32Test method testControlService.
public void testControlService() {
SC_HANDLE scmHandle = Advapi32.INSTANCE.OpenSCManager(null, null, Winsvc.SC_MANAGER_CONNECT);
assertNotNull(scmHandle);
SC_HANDLE serviceHandle = Advapi32.INSTANCE.OpenService(scmHandle, "eventlog", Winsvc.SERVICE_QUERY_CONFIG);
assertNotNull(serviceHandle);
Winsvc.SERVICE_STATUS serverStatus = new Winsvc.SERVICE_STATUS();
assertNotNull(serviceHandle);
assertFalse(Advapi32.INSTANCE.ControlService(serviceHandle, Winsvc.SERVICE_CONTROL_STOP, serverStatus));
assertEquals(W32Errors.ERROR_ACCESS_DENIED, Kernel32.INSTANCE.GetLastError());
assertTrue(Advapi32.INSTANCE.CloseServiceHandle(serviceHandle));
assertTrue(Advapi32.INSTANCE.CloseServiceHandle(scmHandle));
}
Aggregations