我不认为(重新)编写 DLL 是最简单的方法。为什么不使用WMI来检索想要的信息(在这种情况下是打印机)?
以下代码用于检索所有本地安装的打印机:(从此处
借用的代码示例)
ManagementScope objScope = new ManagementScope(ManagementPath.DefaultPath); //For the local Access
objScope.Connect();
SelectQuery selectQuery = new SelectQuery();
selectQuery.QueryString = "Select * from win32_Printer";
ManagementObjectSearcher MOS = new ManagementObjectSearcher(objScope, selectQuery);
ManagementObjectCollection MOC = MOS.Get();
foreach (ManagementObject mo in MOC) {
listBox1.Items.Add(mo["Name"].ToString().ToUpper());
}
要获得跨域已知的打印机,请使用以下命令:
ConnectionOptions objConnection = new ConnectionOptions();
objConnection.Username = "USERNAME";
objConnection.Password = "PASSWORD";
objConnection.Authority = "ntlmdomain:DDI"; //Where DDI is the name of my domain
// Make sure the user you specified have enough permission to access the resource.
ManagementScope objScope = new ManagementScope(@"\\10.0.0.4\root\cimv2",objConnection); //For the local Access
objScope.Connect();
SelectQuery selectQuery = new SelectQuery();
selectQuery.QueryString = "Select * from win32_Printer";
ManagementObjectSearcher MOS = new ManagementObjectSearcher(objScope, selectQuery);
ManagementObjectCollection MOC = MOS.Get();
foreach (ManagementObject mo in MOC) {
listBox1.Items.Add(mo["Name"].ToString().ToUpper());
}
当然,由于您没有指定任何标准,因此该列表不会像您希望的那样“过滤”。但我相信你可以从这里自己管理。