Search in sources :

Example 61 with Advapi32

use of com.sun.jna.platform.win32.Advapi32 in project jna by java-native-access.

the class Advapi32Util method registryCreateKey.

/**
	 * Create a registry key.
	 *
	 * @param root
	 *            Root key.
	 * @param parentPath
	 *            Path to an existing registry key.
	 * @param keyName
	 *            Key name.
	 * @return True if the key was created, false otherwise.
	 */
public static boolean registryCreateKey(HKEY root, String parentPath, String keyName) {
    HKEYByReference phkKey = new HKEYByReference();
    int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, parentPath, 0, WinNT.KEY_CREATE_SUB_KEY, phkKey);
    if (rc != W32Errors.ERROR_SUCCESS) {
        throw new Win32Exception(rc);
    }
    try {
        return registryCreateKey(phkKey.getValue(), keyName);
    } finally {
        rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue());
        if (rc != W32Errors.ERROR_SUCCESS) {
            throw new Win32Exception(rc);
        }
    }
}
Also used : HKEYByReference(com.sun.jna.platform.win32.WinReg.HKEYByReference)

Example 62 with Advapi32

use of com.sun.jna.platform.win32.Advapi32 in project jna by java-native-access.

the class Advapi32Util method registryGetLongValue.

/**
	 * Get a registry QWORD value.
	 *
	 * @param root
	 *            Root key.
	 * @param key
	 *            Registry key path.
	 * @param value
	 *            Name of the value to retrieve.
	 * @return Integer value.
	 */
public static long registryGetLongValue(HKEY root, String key, String value) {
    HKEYByReference phkKey = new HKEYByReference();
    int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, key, 0, WinNT.KEY_READ, phkKey);
    if (rc != W32Errors.ERROR_SUCCESS) {
        throw new Win32Exception(rc);
    }
    try {
        return registryGetLongValue(phkKey.getValue(), value);
    } finally {
        rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue());
        if (rc != W32Errors.ERROR_SUCCESS) {
            throw new Win32Exception(rc);
        }
    }
}
Also used : HKEYByReference(com.sun.jna.platform.win32.WinReg.HKEYByReference)

Example 63 with Advapi32

use of com.sun.jna.platform.win32.Advapi32 in project symmetric-ds by JumpMind.

the class WindowsService method isRunning.

@Override
public boolean isRunning() {
    Advapi32 advapi = Advapi32.INSTANCE;
    SC_HANDLE manager = advapi.OpenSCManager(null, null, Winsvc.SC_MANAGER_ENUMERATE_SERVICE);
    if (manager == null) {
        throwException("OpenSCManager");
    } else {
        SC_HANDLE service = advapi.OpenService(manager, config.getName(), Winsvc.SERVICE_QUERY_STATUS);
        if (service != null) {
            IntByReference bytesNeeded = new IntByReference();
            advapi.QueryServiceStatusEx(service, SC_STATUS_TYPE.SC_STATUS_PROCESS_INFO, null, 0, bytesNeeded);
            SERVICE_STATUS_PROCESS status = new SERVICE_STATUS_PROCESS(bytesNeeded.getValue());
            if (!advapi.QueryServiceStatusEx(service, SC_STATUS_TYPE.SC_STATUS_PROCESS_INFO, status, status.size(), bytesNeeded)) {
                throwException("QueryServiceStatusEx");
            }
            closeServiceHandle(service);
            closeServiceHandle(manager);
            return (status.dwCurrentState == Winsvc.SERVICE_RUNNING);
        }
        closeServiceHandle(manager);
    }
    return super.isRunning();
}
Also used : SERVICE_STATUS_PROCESS(com.sun.jna.platform.win32.Winsvc.SERVICE_STATUS_PROCESS) IntByReference(com.sun.jna.ptr.IntByReference) SC_HANDLE(com.sun.jna.platform.win32.Winsvc.SC_HANDLE) Advapi32(com.sun.jna.platform.win32.Advapi32)

Example 64 with Advapi32

use of com.sun.jna.platform.win32.Advapi32 in project symmetric-ds by JumpMind.

the class WindowsService method logEvent.

protected void logEvent(int eventType, String message) {
    HANDLE eventHandle = getEventHandle();
    if (eventHandle != null) {
        String[] messageArray = { message };
        Advapi32.INSTANCE.ReportEvent(eventHandle, eventType, 0, 0, null, 1, 0, messageArray, null);
    }
}
Also used : WString(com.sun.jna.WString) SERVICE_STATUS_HANDLE(org.jumpmind.symmetric.wrapper.jna.Advapi32Ex.SERVICE_STATUS_HANDLE) SC_HANDLE(com.sun.jna.platform.win32.Winsvc.SC_HANDLE) HANDLE(com.sun.jna.platform.win32.WinNT.HANDLE)

Example 65 with Advapi32

use of com.sun.jna.platform.win32.Advapi32 in project jna by java-native-access.

the class W32Service method queryStatus.

/**
	 * Retrieves the current status of the specified service based on the specified information level.
	 * @return 
	 *  Service status information
	 */
public SERVICE_STATUS_PROCESS queryStatus() {
    IntByReference size = new IntByReference();
    Advapi32.INSTANCE.QueryServiceStatusEx(_handle, SC_STATUS_TYPE.SC_STATUS_PROCESS_INFO, null, 0, size);
    SERVICE_STATUS_PROCESS status = new SERVICE_STATUS_PROCESS(size.getValue());
    if (!Advapi32.INSTANCE.QueryServiceStatusEx(_handle, SC_STATUS_TYPE.SC_STATUS_PROCESS_INFO, status, status.size(), size)) {
        throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
    }
    return status;
}
Also used : SERVICE_STATUS_PROCESS(com.sun.jna.platform.win32.Winsvc.SERVICE_STATUS_PROCESS) 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