nicoriff / ORMi

A Light-ORM for accesing WMI
MIT License
209 stars 28 forks source link

Remote machine #8

Closed pavlovsg closed 5 years ago

pavlovsg commented 5 years ago

Can ORMi access WMI remotely?

WmiLight code, as an example:

var cred = new NetworkCredential("USERNAME", "PASSWORD", "DOMAIN");

using (WmiConnection con = new WmiConnection(@"\\MACHINENAME\root\cimv2", cred, opt))
{
    foreach (WmiObject partition in con.CreateQuery("SELECT * FROM Win32_DiskPartition"))
    {
        Console.WriteLine(partition["Name"]);
    }
}
nicoriff commented 5 years ago

Yes you can, but there is no way still to open a connection with specific credentials from code. What you can do instead is run the process with the desired credentials and create the connection just like in your WmiLight example: WMIHelper helper = new WMIHelper(@"\\MACHINENAME\root\cimv2");. I have in backlog to add that functionality but haven't done it yet. It requieres changing some stuff.