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);
}
}
}
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);
}
}
}
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();
}
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);
}
}
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;
}
Aggregations