开发者

Java accessing WMI as a particular user

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.


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


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

  • runas manpage
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜