Search in sources :

Example 76 with IntByReference

use of com.sun.jna.ptr.IntByReference 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)

Example 77 with IntByReference

use of com.sun.jna.ptr.IntByReference in project jna by java-native-access.

the class WevtapiUtil method EvtFormatMessage.

/**
     * Formats a message string.
     *
     * @param publisherMetadata [in] A handle to the provider's metadata that
     *                          the {@link Wevtapi#EvtOpenPublisherMetadata} function returns. The handle acts as
     *                          a formatting context for the event or message identifier.
     *                          <p>
     *                          You can set this parameter to NULL if the Windows Event Collector service forwarded
     *                          the event. Forwarded events include a RenderingInfo section that contains the rendered
     *                          message strings. You can also set this parameter to NULL if the event property that
     *                          you are formatting is defined in the Winmeta.xml file (for example, if level is set
     *                          to win:Error). In the latter case, the service uses the Winmeta provider as
     *                          the formatting context and will format only those message strings that you reference
     *                          in your event that are defined in the Winmeta.xml file.
     * @param event             [in] A handle to an event. The Flags parameter specifies the message string in
     *                          the event that you want to format. This parameter must be NULL if the Flags parameter
     *                          is set to EvtFormatMessageId.
     * @param messageId         [in] The resource identifier of the message string that you want to format.
     *                          To get the resource identifier for a message string, call
     *                          the {@link Wevtapi#EvtGetPublisherMetadataProperty} function. Set this parameter only
     *                          if the Flags parameter is set to EvtFormatMessageId.
     * @param valueCount        [in] The number of values in the Values parameter.
     * @param values            [in] An array of insertion values to use when formatting the event's message string.
     *                          Typically, you set this parameter to NULL and the function gets the insertion values
     *                          from the event data itself. You would use this parameter to override the default
     *                          behavior and supply the insertion values to use. For example, you might use this
     *                          parameter if you wanted to resolve a SID to a principal name before inserting the value.
     *                          <p>
     *                          To override the insertion values, the Flags parameter must be set to
     *                          {@link Winevt.EVT_FORMAT_MESSAGE_FLAGS#EvtFormatMessageEvent},
     *                          {@link Winevt.EVT_FORMAT_MESSAGE_FLAGS#EvtFormatMessageXml}, or
     *                          {@link Winevt.EVT_FORMAT_MESSAGE_FLAGS#EvtFormatMessageId}, If Flags is set to
     *                          {@link Winevt.EVT_FORMAT_MESSAGE_FLAGS#EvtFormatMessageId}, the resource identifier
     *                          must identify the event's message string.
     * @param flags             [in] A flag that specifies the message string in the event to format. For possible
     *                          values, see the {@link Winevt.EVT_FORMAT_MESSAGE_FLAGS} enumeration.
     * @return Formatted message string
     */
public static String EvtFormatMessage(EVT_HANDLE publisherMetadata, EVT_HANDLE event, int messageId, int valueCount, EVT_VARIANT[] values, int flags) {
    boolean result;
    IntByReference bufferUsed = new IntByReference();
    result = Wevtapi.INSTANCE.EvtFormatMessage(publisherMetadata, event, messageId, valueCount, values, flags, 0, null, bufferUsed);
    int errorCode = Kernel32.INSTANCE.GetLastError();
    if ((!result) && errorCode != Kernel32.ERROR_INSUFFICIENT_BUFFER) {
        throw new Win32Exception(errorCode);
    }
    char[] buffer = new char[bufferUsed.getValue()];
    result = Wevtapi.INSTANCE.EvtFormatMessage(publisherMetadata, event, messageId, valueCount, values, flags, buffer.length, buffer, bufferUsed);
    if (!result) {
        throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
    }
    return Native.toString(buffer);
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference)

Example 78 with IntByReference

use of com.sun.jna.ptr.IntByReference in project jna by java-native-access.

the class WevtapiUtil method EvtNextPublisherId.

/**
     * Gets the identifier of a provider from the enumerator.
     *
     * @param publisherEnum [in] A handle to the registered providers enumerator that
     *                      the {@link Wevtapi#EvtOpenPublisherEnum} function returns.
     * @return The name of the registered provider.
     */
public static String EvtNextPublisherId(EVT_HANDLE publisherEnum) {
    IntByReference publisherIdBufferUsed = new IntByReference();
    boolean result = Wevtapi.INSTANCE.EvtNextPublisherId(publisherEnum, 0, null, publisherIdBufferUsed);
    int errorCode = Kernel32.INSTANCE.GetLastError();
    if ((!result) && errorCode != Kernel32.ERROR_INSUFFICIENT_BUFFER) {
        throw new Win32Exception(errorCode);
    }
    char[] publisherIdBuffer = new char[publisherIdBufferUsed.getValue()];
    result = Wevtapi.INSTANCE.EvtNextPublisherId(publisherEnum, publisherIdBuffer.length, publisherIdBuffer, publisherIdBufferUsed);
    if (!result) {
        throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
    }
    return Native.toString(publisherIdBuffer);
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference)

Example 79 with IntByReference

use of com.sun.jna.ptr.IntByReference in project jna by java-native-access.

the class WevtapiUtil method EvtGetChannelConfigProperty.

/**
     * Gets the specified channel configuration property.
     *
     * @param channelHandle [in] A handle to the channel's configuration properties that
     *                      the {@link Wevtapi#EvtOpenChannelConfig} function returns.
     * @param propertyId    [in] The identifier of the channel property to retrieve. For a list of property
     *                      identifiers, see the {@link Winevt.EVT_CHANNEL_CONFIG_PROPERTY_ID} enumeration.
     * @return EVT_VARIANT(already reading from native memory)
     */
public static EVT_VARIANT EvtGetChannelConfigProperty(EVT_HANDLE channelHandle, int propertyId) {
    IntByReference propertyValueBufferUsed = new IntByReference();
    boolean result = Wevtapi.INSTANCE.EvtGetChannelConfigProperty(channelHandle, propertyId, 0, 0, null, propertyValueBufferUsed);
    int errorCode = Kernel32.INSTANCE.GetLastError();
    if ((!result) && errorCode != Kernel32.ERROR_INSUFFICIENT_BUFFER) {
        throw new Win32Exception(errorCode);
    }
    Memory propertyValueBuffer = new Memory(propertyValueBufferUsed.getValue());
    result = Wevtapi.INSTANCE.EvtGetChannelConfigProperty(channelHandle, propertyId, 0, (int) propertyValueBuffer.size(), propertyValueBuffer, propertyValueBufferUsed);
    if (!result) {
        throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
    }
    EVT_VARIANT resultEvt = new EVT_VARIANT(propertyValueBuffer);
    resultEvt.read();
    return resultEvt;
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) EVT_VARIANT(com.sun.jna.platform.win32.Winevt.EVT_VARIANT) Memory(com.sun.jna.Memory)

Example 80 with IntByReference

use of com.sun.jna.ptr.IntByReference in project jna by java-native-access.

the class WevtapiUtil method EvtGetExtendedStatus.

/**
     * Gets a text message that contains the extended error information for the current error.
     *
     * @return error information text
     */
public static String EvtGetExtendedStatus() {
    int errorCode;
    IntByReference buffUsed = new IntByReference();
    errorCode = Wevtapi.INSTANCE.EvtGetExtendedStatus(0, null, buffUsed);
    if (errorCode != WinError.ERROR_SUCCESS && errorCode != WinError.ERROR_INSUFFICIENT_BUFFER) {
        throw new Win32Exception(errorCode);
    }
    if (buffUsed.getValue() == 0) {
        return "";
    }
    char[] mem = new char[buffUsed.getValue()];
    errorCode = Wevtapi.INSTANCE.EvtGetExtendedStatus(mem.length, mem, buffUsed);
    if (errorCode != WinError.ERROR_SUCCESS) {
        throw new Win32Exception(errorCode);
    }
    return Native.toString(mem);
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference)

Aggregations

IntByReference (com.sun.jna.ptr.IntByReference)199 PointerByReference (com.sun.jna.ptr.PointerByReference)38 Memory (com.sun.jna.Memory)33 HANDLE (com.sun.jna.platform.win32.WinNT.HANDLE)26 File (java.io.File)19 Pointer (com.sun.jna.Pointer)15 Test (org.junit.Test)15 ArrayList (java.util.ArrayList)14 PSID (com.sun.jna.platform.win32.WinNT.PSID)13 HANDLEByReference (com.sun.jna.platform.win32.WinNT.HANDLEByReference)11 SC_HANDLE (com.sun.jna.platform.win32.Winsvc.SC_HANDLE)11 HKEYByReference (com.sun.jna.platform.win32.WinReg.HKEYByReference)9 ACL (com.sun.jna.platform.win32.WinNT.ACL)8 Advapi32 (com.sun.jna.platform.win32.Advapi32)7 HRESULT (com.sun.jna.platform.win32.WinNT.HRESULT)7 ACCESS_ALLOWED_ACE (com.sun.jna.platform.win32.WinNT.ACCESS_ALLOWED_ACE)6 SECURITY_DESCRIPTOR (com.sun.jna.platform.win32.WinNT.SECURITY_DESCRIPTOR)6 HKEY (com.sun.jna.platform.win32.WinReg.HKEY)6 EVT_HANDLE (com.sun.jna.platform.win32.Winevt.EVT_HANDLE)6 CredHandle (com.sun.jna.platform.win32.Sspi.CredHandle)5