use of com.sun.jna.platform.win32.Advapi32 in project jna by java-native-access.
the class Advapi32Test method testBackupEventLog.
/*
public void testClearEventLog() {
HANDLE h = Advapi32.INSTANCE.OpenEventLog(null, "Application");
assertFalse(h.equals(WinBase.INVALID_HANDLE_VALUE));
IntByReference before = new IntByReference();
assertTrue(Advapi32.INSTANCE.GetNumberOfEventLogRecords(h, before));
assertTrue(before.getValue() >= 0);
assertTrue(Advapi32.INSTANCE.ClearEventLog(h, null));
IntByReference after = new IntByReference();
assertTrue(Advapi32.INSTANCE.GetNumberOfEventLogRecords(h, after));
assertTrue(after.getValue() < before.getValue() || before.getValue() == 0);
assertTrue(Advapi32.INSTANCE.CloseEventLog(h));
}
*/
public void testBackupEventLog() {
HANDLE h = Advapi32.INSTANCE.OpenEventLog(null, "Application");
assertNotNull(h);
String backupFileName = Kernel32Util.getTempPath() + "\\JNADevEventLog.bak";
File f = new File(backupFileName);
if (f.exists()) {
f.delete();
}
assertTrue(Advapi32.INSTANCE.BackupEventLog(h, backupFileName));
HANDLE hBackup = Advapi32.INSTANCE.OpenBackupEventLog(null, backupFileName);
assertNotNull(hBackup);
IntByReference n = new IntByReference();
assertTrue(Advapi32.INSTANCE.GetNumberOfEventLogRecords(hBackup, n));
assertTrue(n.getValue() >= 0);
assertTrue(Advapi32.INSTANCE.CloseEventLog(h));
assertTrue(Advapi32.INSTANCE.CloseEventLog(hBackup));
}
use of com.sun.jna.platform.win32.Advapi32 in project jna by java-native-access.
the class Advapi32Test method testMapGenericAllMask.
public void testMapGenericAllMask() {
final GENERIC_MAPPING mapping = new GENERIC_MAPPING();
mapping.genericRead = new DWORD(FILE_GENERIC_READ);
mapping.genericWrite = new DWORD(FILE_GENERIC_WRITE);
mapping.genericExecute = new DWORD(FILE_GENERIC_EXECUTE);
mapping.genericAll = new DWORD(FILE_ALL_ACCESS);
final DWORDByReference rights = new DWORDByReference(new DWORD(GENERIC_ALL));
Advapi32.INSTANCE.MapGenericMask(rights, mapping);
assertEquals(FILE_ALL_ACCESS, rights.getValue().intValue());
assertTrue(GENERIC_ALL != (rights.getValue().intValue() & GENERIC_ALL));
}
use of com.sun.jna.platform.win32.Advapi32 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.Advapi32 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.Advapi32 in project jna by java-native-access.
the class Advapi32Test method testRegSetValueEx_DWORD.
public void testRegSetValueEx_DWORD() {
HKEYByReference phKey = new HKEYByReference();
// create parent key
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegOpenKeyEx(WinReg.HKEY_CURRENT_USER, "Software", 0, WinNT.KEY_WRITE | WinNT.KEY_READ, phKey));
HKEYByReference phkTest = new HKEYByReference();
IntByReference lpdwDisposition = new IntByReference();
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegCreateKeyEx(phKey.getValue(), "JNAAdvapi32Test", 0, null, 0, WinNT.KEY_ALL_ACCESS, null, phkTest, lpdwDisposition));
// write a REG_DWORD value
int value = 42145;
byte[] data = new byte[4];
data[0] = (byte) (value & 0xff);
data[1] = (byte) ((value >> 8) & 0xff);
data[2] = (byte) ((value >> 16) & 0xff);
data[3] = (byte) ((value >> 24) & 0xff);
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegSetValueEx(phkTest.getValue(), "DWORD", 0, WinNT.REG_DWORD, data, 4));
// re-read the REG_DWORD value
IntByReference lpType = new IntByReference();
IntByReference lpcbData = new IntByReference();
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegQueryValueEx(phkTest.getValue(), "DWORD", 0, lpType, (char[]) null, lpcbData));
assertEquals(WinNT.REG_DWORD, lpType.getValue());
assertEquals(4, lpcbData.getValue());
IntByReference valueRead = new IntByReference();
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegQueryValueEx(phkTest.getValue(), "DWORD", 0, lpType, valueRead, lpcbData));
assertEquals(value, valueRead.getValue());
// delete the test key
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegCloseKey(phkTest.getValue()));
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegDeleteKey(phKey.getValue(), "JNAAdvapi32Test"));
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegCloseKey(phKey.getValue()));
}
Aggregations