Search in sources :

Example 66 with Advapi32

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());
    }
}
Also used : SERVICE_FAILURE_ACTIONS_FLAG(com.sun.jna.platform.win32.Winsvc.SERVICE_FAILURE_ACTIONS_FLAG)

Example 67 with Advapi32

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;
}
Also used : SC_HANDLE(com.sun.jna.platform.win32.Winsvc.SC_HANDLE) Advapi32(com.sun.jna.platform.win32.Advapi32)

Example 68 with Advapi32

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());
    }
}
Also used : DomainTrust(com.sun.jna.platform.win32.Netapi32Util.DomainTrust)

Example 69 with Advapi32

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()));
}
Also used : HKEYByReference(com.sun.jna.platform.win32.WinReg.HKEYByReference) IntByReference(com.sun.jna.ptr.IntByReference) KEY_BASIC_INFORMATION(com.sun.jna.platform.win32.Wdm.KEY_BASIC_INFORMATION)

Example 70 with Advapi32

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()));
}
Also used : LSA_FOREST_TRUST_RECORD(com.sun.jna.platform.win32.NTSecApi.LSA_FOREST_TRUST_RECORD) PLSA_FOREST_TRUST_RECORD(com.sun.jna.platform.win32.NTSecApi.PLSA_FOREST_TRUST_RECORD) PLSA_FOREST_TRUST_RECORD(com.sun.jna.platform.win32.NTSecApi.PLSA_FOREST_TRUST_RECORD) PLSA_FOREST_TRUST_INFORMATION(com.sun.jna.platform.win32.NTSecApi.PLSA_FOREST_TRUST_INFORMATION) PointerByReference(com.sun.jna.ptr.PointerByReference) IntByReference(com.sun.jna.ptr.IntByReference)

Aggregations

IntByReference (com.sun.jna.ptr.IntByReference)51 SC_HANDLE (com.sun.jna.platform.win32.Winsvc.SC_HANDLE)39 HANDLE (com.sun.jna.platform.win32.WinNT.HANDLE)31 HKEYByReference (com.sun.jna.platform.win32.WinReg.HKEYByReference)31 HANDLEByReference (com.sun.jna.platform.win32.WinNT.HANDLEByReference)23 PSID (com.sun.jna.platform.win32.WinNT.PSID)20 PointerByReference (com.sun.jna.ptr.PointerByReference)20 Advapi32 (com.sun.jna.platform.win32.Advapi32)15 DWORD (com.sun.jna.platform.win32.WinDef.DWORD)15 File (java.io.File)15 Memory (com.sun.jna.Memory)13 HKEY (com.sun.jna.platform.win32.WinReg.HKEY)13 PSIDByReference (com.sun.jna.platform.win32.WinNT.PSIDByReference)10 DWORDByReference (com.sun.jna.platform.win32.WinDef.DWORDByReference)9 ACL (com.sun.jna.platform.win32.WinNT.ACL)9 SECURITY_DESCRIPTOR (com.sun.jna.platform.win32.WinNT.SECURITY_DESCRIPTOR)7 Pointer (com.sun.jna.Pointer)6 ACCESS_ALLOWED_ACE (com.sun.jna.platform.win32.WinNT.ACCESS_ALLOWED_ACE)6 GENERIC_MAPPING (com.sun.jna.platform.win32.WinNT.GENERIC_MAPPING)6 BOOLByReference (com.sun.jna.platform.win32.WinDef.BOOLByReference)5