标签:
Public Function FindPrinter(strPrinterName As String) As Boolean Dim pa As String Dim length As Integer Dim objRegistry As Object Dim arrSubkeys As Variant Dim subkey As Variant Dim kk As Variant On Error Resume Next Set objRegistry = GetObject("winmgmts:\\.\root\default:StdRegProv") objRegistry.EnumValues &H80000001, "Software\Microsoft\Windows NT\CurrentVersion\PrinterPorts", arrSubkeys FindPrinter = False length = Len(strPrinter) For Each subkey In arrSubkeys objRegistry.GetStringValue &H80000001, "Software\Microsoft\Windows NT\CurrentVersion\PrinterPorts\", subkey, kk pa = subkey & " on " & Mid(kk, InStr(kk, ",") + 1, InStr(kk, ":,") - InStr(kk, ",")) If Left(pa, length) = strPrinterName Then FindPrinter = True Application.ActivePrinter = pa Exit For End If Next If FindPrinter = False Then MsgBox "没有找到打印机。" End If End Function
标签:
原文地址:http://www.cnblogs.com/mymeng_feng/p/4359270.html