Reputation: 1
I have a question wmi4java lib: Can it connect to a remote Win machine and run WMI queries there? Searched the documentation and even looked at source code of the main class and found nothing that points to remote connection with authentication.
The github page gives no examples on connecting to a remote machine: https://github.com/profesorfalken/WMI4Java
and javadoc for Class WMI4Java mentions localhost only:
https://jar-download.com/java-documentation-javadoc.php?a=WMI4Java&g=com.profesorfalken&v=1.6
e.g: WMI4Java.get().computerName(".").namespace("root/cimv2").getWMIObject("Win32_BaseBoard");
If I specify another host (aka computerName("10.10.172.214")...) it will obviously throw exception since it found no credential.
I know this lib uses internally jPowerShell so there must be a way. Thank you.
Upvotes: 0
Views: 1146
Reputation: 1
Found how to to it via getRawWMIObjectOutput call. This is not ideal as it doesn't look elegant and you get output as string instead of neat map of properties. But anyway here it is:
_log.info("\n-- Get raw output in String format on remote host (Win32_Process) --\n");
wmiObjectPropsRaw = WMI4Java.get()
.computerName("10.10.172.214")
.namespace("root/cimv2")
.filters(Arrays.asList("$_.Name -eq \"lsass.exe\""))
.getRawWMIObjectOutput(
"Win32_Process"
+ " -Impersonation 3"
+ " -Credential (new-object -typename System.Management.Automation.PSCredential"
+ " -argumentlist Administrator, "
+ " (ConvertTo-SecureString Sysdreamworks123 -AsPlainText -Force))");
_log.info(wmiObjectPropsRaw + "\n");
Upvotes: 0