try { ConnectionOptions connection = new ConnectionOptions(); connection.Username = "username"; connection.Password = "password"; connection.Authority = "ntlmdomain:DOMAINNAME"; connection.Impersonation = ImpersonationLevel.Impersonate; ManagementScope scope = new ManagementScope("\\\\Servers' public ip\\root\\CIMV2", connection); scope.Connect(); ManagementObject classInstance = new ManagementObject(scope, new ManagementPath("Win32_Printer.DeviceID='\\\\Servers' public ip\\Printer name'"), null); // no method in-parameters to define // Execute the method and obtain the return values. ManagementBaseObject outParams = classInstance.InvokeMethod("PrintTestPage", null, null); // List outParams Console.WriteLine("Out parameters:"); Console.WriteLine("ReturnValue: " + outParams["ReturnValue"]); } catch (ManagementException err) { Console.WriteLine("An error occurred while trying to execute the WMI method: " + err.ErrorCode); } catch (System.UnauthorizedAccessException unauthorizedErr) { Console.WriteLine("Connection error (user name or password might be incorrect): " + unauthorizedErr.Message); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)