Question

I am trying to write a Java application that will query the WMI on windows hosts within domains to obtain their mac address and dns name. I can run the script via exec or using a few of the jars I have found on the internet but none that I have seen allow me to impersonate an AD account when I run the query.

I would like to be able to specify the account that the query runs as(an admin of that domain), the program may run on a machine that is not in the domain or there might be two domains that I will query.

I've looked at JACOB and com4J but can't find an example of it doing impersonation.

Also I'm not an advanced programmer by any means so apologies if I've missed something glaringly obvious

Thanks in advance.

Was it helpful?

Solution

If you use the ConnectServer method of SWbemLocator you can specify the username and password to connect to the other machine as. However, you cannot use this method to connect to the machine your running the code on.

If your just calling a script, consider using Python. There is a nice example of how to do this using python in the wmi Cookbook

OTHER TIPS

You can wrap the exec command line with a call to runas, which will run the command as the specified user.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top