1.获取网卡地址:
1 private string GetMacAddress() 2 { 3 string code = null; 4 SelectQuery query = new SelectQuery("select * from Win32_ComputerSystemProduct"); 5 using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(query)) 6 { 7 foreach (var item in searcher.Get()) 8 { 9 using (item) code = item["UUID"].ToString(); 10 } 11 } 12 return code; 13 }
2.获取本机系统打印机:
1 [DllImport("winspool.drv")] 2 public static extern bool SetDefaultPrinter(String Name); //调用win api将指定名称的打印机设置为默认打印机 3 4 private static PrintDocument pd = new PrintDocument(); 5 //获取本机默认打印机名称 6 public static String DefaultPrinter() 7 { 8 return pd.PrinterSettings.PrinterName; 9 } 10 public static List<String> GetLocalPrinters() 11 { 12 List<String> fPrinters = new List<String>(); 13 fPrinters.Add(DefaultPrinter()); //默认打印机始终出现在列表的第一项 14 foreach (String fPrinterName in PrinterSettings.InstalledPrinters) 15 { 16 if (!fPrinters.Contains(fPrinterName)) 17 { 18 fPrinters.Add(fPrinterName); 19 } 20 } 21 return fPrinters; 22 }
显示在下拉列表中
1 List<String> list = LocalPrinter.GetLocalPrinters(); //获得系统中的打印机列表 2 foreach (String s in list) 3 { 4 printerComboBox.Items.Add(s); //将打印机名称添加到下拉框中 5 } 6 printerComboBox.SelectedIndex = 0;