Default Printer

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I would like to Update the default printer in the Printer Dialog box. For some reason it's not updating throughout Windows or when I close th app and restart it returns to the previous default printer

Is there a registry setting I need to set or is there a Printer Dialog property that cna do this for me

Thanks in advance

David
 
Wow! That seems like an awful lot of code to set the default printer. Isn't there a registry key that I can just edit?
 
Hi David

Just to pre-empt Herfried, the danger of 'just editing' a registry key is
that such keys can change, over time and between operating systems.
Interfaces provide a contract between client and server, and as such are
more likely to be supported in the longer term. That said, try

Imports System.Runtime.InteropServices

Public Class MyClass
' SetDefaultPrinter
<DllImport("winspool.drv", SetlastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function SetDefaultPrinter(ByVal pszPrinter As String) As
Boolean
' THIS MUST BE EMPTY
End Function
...

Then you can call

SetDefaultPrinter("name of printer")

HTH

Charles


David said:
Wow! That seems like an awful lot of code to set the default printer.
Isn't there a registry key that I can just edit?
 
I will try that code out. The article I first received was way too long to just change the default printer

I can totally understand that just editing a registry key can be difficult to manage over time but so can managing that code in the article as Windows versions change.

Thanks

David
 
Hi,

Method using wmi. Add a reference to system.management to your app

Dim moReturn As Management.ManagementObjectCollection

Dim moSearch As Management.ManagementObjectSearcher

Dim mo As Management.ManagementObject

moSearch = New Management.ManagementObjectSearcher("Select * from
Win32_Printer")

moReturn = moSearch.Get

For Each mo In moReturn

Dim objReturn As Object

Debug.WriteLine(mo("Name"))

mo.InvokeMethod("SetDefaultPrinter", objReturn)

Next



Ken
 
Back
Top