private void RenamePrinter(string oldName, string newName) { ConnectionOptions options = new ConnectionOptions(); options.Username = username; options.Password = password; options.EnablePrivileges = true; options.Authority = "ntlmdomain:DomainName"; ManagementScope scope = new ManagementScope(@"\\.\root\CIMV2", options); scope.Connect(); SelectQuery query = new SelectQuery("SELECT * FROM Win32_Printer"); ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query); using (ManagementObjectCollection queryCollections = searcher.Get()) { foreach (ManagementObject printer in queryCollections) { if (printer["name"].ToString() == oldName) { { printer.InvokeMethod("RenamePrinter", new object[] { newName }); } return; } } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)