JNI Wrapper and WMI

212 views
Skip to first unread message

p...@tonesoft.com

unread,
Jan 24, 2014, 5:59:45 PM1/24/14
to jniwrapp...@teamdev.com
We need to access the WMI API from Java. Does JNIWrapper allow easy access to that API? I didn't see anything in the demo's

Sergei Piletsky

unread,
Jan 28, 2014, 11:35:06 AM1/28/14
to p...@tonesoft.com, jniwrapp...@teamdev.com
Hi,

I think that it should be possible to integrate with WMI somehow using JNIWrapper, but I'm not sure it's an easiest way. 

For integration with WMI you could use COM API for WMI: http://msdn.microsoft.com/en-us/library/aa389276.aspx and for such integration you will need our ComfyJ: http://www.teamdev.com/comfyj product instead of JNIWrapper.

The first step will be to create the Java wrappers for the WMI COM type library. It can be done using Codegen for ComfyJ application (Chapter #5: http://www.teamdev.com/downloads/comfyj/docs/ComfyJ-PGuide.html#CodeGen). In order to start this application you need to run CodegeForComfyJ.bat file, as it’s shown on the screenshot below:
Inline image 1

After starting Codegen for ComfyJ you will need to select the “Generate for a registered COM type library” mode and then find WMI COM library in the list, for example using quick search feature:
Inline image 2

Then, after specifying the destination folder and package name, application will create the complete set of wrappers for the WMI COM Type library.  

The last step is to include the generated Java classes to the class path of your application. And WMI integration itself will look pretty much the same as those WMI examples which you can find in MSDN:
public class GettingWMIDataFromLocaComputer {
    static final public int RPC_C_AUTHN_LEVEL_NONE = 1;
    static final int RPC_C_IMP_LEVEL_IDENTIFY = 2;
    static final int EOAC_NONE = 0;

    static void coInitializeSecurity() {
        Function function = OleFunctions.getInstance().getFunction("CoInitializeSecurity");
        HResult result = new HResult();
        function.invoke(result, new Parameter[] {
            new Handle(), // PSECURITY_DESCRIPTOR pVoid,
            new Int32(-1),  // LONG cAuthSvc,
            new Handle(), // SOLE_AUTHENTICATION_SERVICE* asAuthSvc,
            new Handle(), // void* pReserved1,
            new UInt32(RPC_C_AUTHN_LEVEL_NONE), // DWORD dwAuthnLevel,
            new UInt32(RPC_C_IMP_LEVEL_IDENTIFY), // DWORD dwImpLevel,
            new Handle(), // SOLE_AUTHENTICATION_LIST* pAuthList,
            new UInt32(EOAC_NONE), // DWORD dwCapabilities,
            new Handle()  // void* pReserved3
        });
        ComException.checkResult(result);
    }

    public static void main(String[] args) {
        ComFunctions.coInitializeEx(CoInit.MULTITHREADED);
        coInitializeSecurity();
        ISWbemLocator wbemLocator = SWbemLocator.create(ClsCtx.INPROC_SERVER);
        wbemLocator.connectServer();
        //...
    }
}

Please let me know if you have any further question.

Sincerely,
Serge


On Sat, Jan 25, 2014 at 12:59 AM, <p...@tonesoft.com> wrote:
We need to access the WMI API from Java. Does JNIWrapper allow easy access to that API? I didn't see anything in the demo's

--
You received this message because you are subscribed to the Google Groups "JNIWrapper Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jniwrapper-for...@teamdev.com.
To post to this group, send email to jniwrapp...@teamdev.com.
Visit this group at http://groups.google.com/a/teamdev.com/group/jniwrapper-forum/.
For more options, visit https://groups.google.com/a/teamdev.com/groups/opt_out.

screen1.png
screen2.png
Reply all
Reply to author
Forward
0 new messages