07-03-21 07:43 PM
Answered! Go to Answer.
08-03-21 01:23 AM
' pn is an Input Parameter, which is the printer name to set as default.
If pn = "" Then
return
End If
Dim mos As New ManagementObjectSearcher( _
"SELECT * FROM Win32_Printer")
Dim moc As ManagementObjectCollection = mos.Get()
Dim mo As ManagementObject
For Each mo In moc
If CStr(mo("Name")) = pn Then
Dim mbo As ManagementBaseObject = _
mo.InvokeMethod("SetDefaultPrinter", Nothing, Nothing)
Dim ret As Long = Convert.ToInt64(mbo("returnValue"))
If ret <> 0 Then
Throw New Exception("Failed to set default printer.")
End If
return
End If
Next mo
Throw New Exception("Printer not found.")
I hope this will help 🙂
------------------------------
Kota Suto
Japan
------------------------------
08-03-21 01:23 AM
' pn is an Input Parameter, which is the printer name to set as default.
If pn = "" Then
return
End If
Dim mos As New ManagementObjectSearcher( _
"SELECT * FROM Win32_Printer")
Dim moc As ManagementObjectCollection = mos.Get()
Dim mo As ManagementObject
For Each mo In moc
If CStr(mo("Name")) = pn Then
Dim mbo As ManagementBaseObject = _
mo.InvokeMethod("SetDefaultPrinter", Nothing, Nothing)
Dim ret As Long = Convert.ToInt64(mbo("returnValue"))
If ret <> 0 Then
Throw New Exception("Failed to set default printer.")
End If
return
End If
Next mo
Throw New Exception("Printer not found.")
I hope this will help 🙂
------------------------------
Kota Suto
Japan
------------------------------
08-03-21 09:15 AM
31-10-23 09:00 AM
Hi Kota ,
Hope you are doing good, Do you know how to set network printer as default?
The Code is able to set default only which are available in windows