tags:

views:

42

answers:

2

Hello,

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.

A: 

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

Robert Christie
I've never used python at all but it's an option, Ill try using SWbemLocator and post how I get on - thankyou
Thank you very much - used the SWbemLocator and altered my test app and can query using AD account and pass.
A: 

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

mdma
I tried using runas but it only allows you to either save credentials or enter them as you execute the runas either way I couldn't work out a way of passing the password and one post I read suggested that you actually couldn't pass the password at runtime by design.