use of com.sun.jna.platform.win32.Advapi32 in project jna by java-native-access.
the class W32Service method setFailureActionsFlag.
/**
* Set the failure action flag of the specified service. Corresponds to
* <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms681988.aspx">ChangeServiceConfig2</a>
* with parameter dwInfoLevel set to SERVICE_CONFIG_FAILURE_ACTIONS_FLAG.
*/
public void setFailureActionsFlag(boolean flagValue) {
SERVICE_FAILURE_ACTIONS_FLAG flag = new SERVICE_FAILURE_ACTIONS_FLAG();
flag.fFailureActionsOnNonCrashFailures = flagValue ? 1 : 0;
if (!Advapi32.INSTANCE.ChangeServiceConfig2(_handle, Winsvc.SERVICE_CONFIG_FAILURE_ACTIONS_FLAG, flag)) {
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
}
}
use of com.sun.jna.platform.win32.Advapi32 in project symmetric-ds by JumpMind.
the class WindowsService method openServiceManager.
protected SC_HANDLE openServiceManager() {
Advapi32 advapi = Advapi32.INSTANCE;
SC_HANDLE handle = advapi.OpenSCManager(null, null, Winsvc.SC_MANAGER_ALL_ACCESS);
if (handle == null) {
throwException("OpenSCManager");
}
return handle;
}
use of com.sun.jna.platform.win32.Advapi32 in project jna by java-native-access.
the class Netapi32UtilTest method testGetDomainTrusts.
public void testGetDomainTrusts() {
if (Netapi32Util.getJoinStatus() != LMJoin.NETSETUP_JOIN_STATUS.NetSetupDomainName)
return;
DomainTrust[] trusts = Netapi32Util.getDomainTrusts();
assertTrue(trusts.length >= 0);
for (DomainTrust trust : trusts) {
assertTrue(trust.NetbiosDomainName.length() > 0);
assertTrue(trust.DnsDomainName.length() > 0);
assertTrue(Advapi32.INSTANCE.IsValidSid(trust.DomainSid));
assertTrue(trust.isInbound() || trust.isOutbound() || trust.isPrimary());
}
}
use of com.sun.jna.platform.win32.Advapi32 in project jna by java-native-access.
the class NtDllTest method testZwQueryKey.
public void testZwQueryKey() {
// open a key
HKEYByReference phKey = new HKEYByReference();
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegOpenKeyEx(WinReg.HKEY_CURRENT_USER, "Software", 0, WinNT.KEY_WRITE | WinNT.KEY_READ, phKey));
// query key info
IntByReference resultLength = new IntByReference();
assertEquals(NTStatus.STATUS_BUFFER_TOO_SMALL, NtDll.INSTANCE.ZwQueryKey(phKey.getValue(), KEY_INFORMATION_CLASS.KeyBasicInformation, null, 0, resultLength));
assertTrue(resultLength.getValue() > 0);
KEY_BASIC_INFORMATION keyInformation = new KEY_BASIC_INFORMATION(resultLength.getValue());
assertEquals(NTStatus.STATUS_SUCCESS, NtDll.INSTANCE.ZwQueryKey(phKey.getValue(), Wdm.KEY_INFORMATION_CLASS.KeyBasicInformation, keyInformation, resultLength.getValue(), resultLength));
// show
// Keys are case insensitive (https://msdn.microsoft.com/de-de/library/windows/desktop/ms724946(v=vs.85).aspx)
assertEquals("software", keyInformation.getName().toLowerCase());
// close key
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegCloseKey(phKey.getValue()));
}
use of com.sun.jna.platform.win32.Advapi32 in project jna by java-native-access.
the class Netapi32Test method testDsGetForestTrustInformation.
public void testDsGetForestTrustInformation() {
if (Netapi32Util.getJoinStatus() != LMJoin.NETSETUP_JOIN_STATUS.NetSetupDomainName)
return;
String domainController = Netapi32Util.getDCName();
PLSA_FOREST_TRUST_INFORMATION.ByReference pfti = new PLSA_FOREST_TRUST_INFORMATION.ByReference();
assertEquals(W32Errors.NO_ERROR, Netapi32.INSTANCE.DsGetForestTrustInformation(domainController, null, 0, pfti));
assertTrue(pfti.fti.RecordCount >= 0);
for (PLSA_FOREST_TRUST_RECORD precord : pfti.fti.getEntries()) {
LSA_FOREST_TRUST_RECORD.UNION data = precord.tr.u;
switch(precord.tr.ForestTrustType) {
case NTSecApi.ForestTrustTopLevelName:
case NTSecApi.ForestTrustTopLevelNameEx:
assertTrue(data.TopLevelName.Length > 0);
assertTrue(data.TopLevelName.MaximumLength > 0);
assertTrue(data.TopLevelName.MaximumLength >= data.TopLevelName.Length);
assertTrue(data.TopLevelName.getString().length() > 0);
break;
case NTSecApi.ForestTrustDomainInfo:
assertTrue(data.DomainInfo.DnsName.Length > 0);
assertTrue(data.DomainInfo.DnsName.MaximumLength > 0);
assertTrue(data.DomainInfo.DnsName.MaximumLength >= data.DomainInfo.DnsName.Length);
assertTrue(data.DomainInfo.DnsName.getString().length() > 0);
assertTrue(data.DomainInfo.NetbiosName.Length > 0);
assertTrue(data.DomainInfo.NetbiosName.MaximumLength > 0);
assertTrue(data.DomainInfo.NetbiosName.MaximumLength >= data.DomainInfo.NetbiosName.Length);
assertTrue(data.DomainInfo.NetbiosName.getString().length() > 0);
assertTrue(Advapi32.INSTANCE.IsValidSid(data.DomainInfo.Sid));
assertTrue(Advapi32Util.convertSidToStringSid(data.DomainInfo.Sid).startsWith("S-"));
break;
}
}
assertEquals(W32Errors.ERROR_SUCCESS, Netapi32.INSTANCE.NetApiBufferFree(pfti.getPointer()));
}
Aggregations