G
Guest
Hi,
I'm trying to get the default printer using WMI.
I use the following code:
Private Function GetDefaultPrinter() As String
Dim objWMIService As Object
Dim colInstalledPrinters As Object
Dim objPrinter As Object
Dim strComputer As String
Dim strPrinter As String
strComputer = "MyComputerName"
objWMIService =
GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer &
"\root\cimv2")
colInstalledPrinters = objWMIService.ExecQuery("Select * from
Win32_Printer Where Default = True")
For Each objPrinter In colInstalledPrinters
strPrinter = objPrinter.Name()
Next
GetDefaultPrinter = strPrinter
End Function
I've a printer installed as default printer, but the function returns to
printer. What is going wrong?
Many thanks in advance.
Willem
I'm trying to get the default printer using WMI.
I use the following code:
Private Function GetDefaultPrinter() As String
Dim objWMIService As Object
Dim colInstalledPrinters As Object
Dim objPrinter As Object
Dim strComputer As String
Dim strPrinter As String
strComputer = "MyComputerName"
objWMIService =
GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer &
"\root\cimv2")
colInstalledPrinters = objWMIService.ExecQuery("Select * from
Win32_Printer Where Default = True")
For Each objPrinter In colInstalledPrinters
strPrinter = objPrinter.Name()
Next
GetDefaultPrinter = strPrinter
End Function
I've a printer installed as default printer, but the function returns to
printer. What is going wrong?
Many thanks in advance.
Willem