vb中如何获取系统默认打印机的名称?

 我来答
xiufeng0120
推荐于2019-11-13 · TA获得超过1.1万个赞
知道小有建树答主
回答量:119
采纳率:0%
帮助的人:6.5万
展开全部

Const HKLM = &H80000002 '定义根键常数
'其他常用根键 Const HKCR = &H80000000 , Const HKCU = &H80000001
Set oReg = GetObject("winmgmts:\\.\root\default:StdRegProv")
strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths"
oReg.EnumKey HKLM, strKeyPath, arrSubKeys '枚举子项,赋值给数组arrSubKeys
For Each subkey In arrSubKeys
Print subkey
Next

For Each x In Printers
FindPrinter strPrint, x.DeviceName
next

Function FindPrinter(ByRef PrinterName As String, Optional ByVal PrinterDescription As String = "") As Boolean
' 查指定打印机
Dim objRegistry As Object
Dim arrSubKeys As Variant
Dim subkey As Variant
Dim KeyValue As Variant

If Len(PrinterDescription) > 0 Then
Set objRegistry = GetObject("winmgmts:\\.\root\default:StdRegProv")
objRegistry.EnumValues &H80000001, "Software\Microsoft\Windows NT\CurrentVersion\PrinterPorts", arrSubKeys
For Each subkey In arrSubKeys
If InStr(1, subkey, PrinterDescription) Then
objRegistry.GetStringValue &H80000001, "Software\Microsoft\Windows NT\CurrentVersion\PrinterPorts\", subkey, KeyValue
PrinterName = subkey & " 在 " & Mid(KeyValue, InStr(KeyValue, ",") + 1, InStr(KeyValue, ":,") - InStr(KeyValue, ","))
FindPrinter = True
Exit For
End If
Next
Set objRegistry = Nothing
End If
End Function

推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式