Try this for maximum backward compatibility.
[tt]
Private Sub x_Click()
'reference: Microsoft WMI Scripting v1.1 Library
Dim sComputer As String
Dim svc As ISWbemServices
Dim cprt As ISWbemObjectSet
Dim oprt As ISWbemObject
Dim bExistDefault As Boolean
Dim sNameDefault As String
Dim sNameComp As String
'local : ".","127.0.0.1","localhost", computer name
'remote: ip address or computer name
sComputer = "."
bExistDefault = False
sNameDefault = ""
If (sComputer = ".") Or (sComputer = "127.0.0.1") Or (LCase(sComputer) = "localhost") Then
sNameComp = "Localhost"
Else
sNameComp = sComputer
End If
Set svc = GetObject("winmgmts:\\" & sComputer & "\root\cimv2")
Set cprt = svc.execquery("select Name, Attributes from win32_printer")
For Each oprt In cprt
If (oprt.Attributes And &H4) = &H4 Then
bExistDefault = True
sNameDefault = oprt.Name
Exit For
End If
Next
Set cprt = Nothing
Set svc = Nothing
If bExistDefault Then
MsgBox "Computer " & sNameComp & " has an assigned default printer : " & sNameDefault & "."
Else
MsgBox "Computer " & sNameComp & " does not have a default printer assigned."
End If
>>for maximum backward compatibility
>I am not sure what you mean
I refer to detecting &H4 attribute flag. You have added method for later version. But, this check is compatible all along.
I think what bjd4jc is querying is how the WMI method (which won't by default work on admittedly obsolete W9x/NT4 machines) to check the &H4 attribute is more backwards compatible than VB6's Printer.Default method, which works on all platforms on which VB6 works
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.