以编程方式设置打印机共享名称

时间:2015-09-18 23:40:45

标签: c# printing wmi

我已经能够使用System.Management程序集中的ManagementObject成功重命名打印机。

fa := [:a | <whatever>].
fb := [:a :b | <yourcode>].
receiver ifTrue: fa ifFalse: fb

是否有类似的设置打印机的共享名称?

这是我尝试更改的属性的屏幕截图:

enter image description here

1 个答案:

答案 0 :(得分:1)

事实证明我可以直接更改ManagementObject的属性。我就这样做了:

string query = String.Format("SELECT * FROM Win32_Printer WHERE Name = '{0}'", printerName);
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
ManagementObjectCollection collection = searcher.Get();
ManagementObject printer = collection.Cast<ManagementObject>().ElementAt(0);

// The part that changes the printer share name
printer.Properties["ShareName"].Value = newName;
printer.Put();