PDA

Click to See Complete Forum and Search --> : Which one is Default Printer?


OlgaV
Dec 1st, 1999, 03:12 AM
Hi!

Does anyone know how I can check which printer is set as default? Is there an API that does it?

I also need to find a way of closing a printer. Again, is there an API that does that?

Thank you! Thank you!

Olga

Aaron Young
Dec 1st, 1999, 03:29 AM
The Printer Object Defaults to the Default Printer when your Application Starts.

Can you explain what you mean by Closing a Printer?

You finish a Print by Issuing Printer.EndDoc, or Cancel the Last Page by Issuing Printer.KillDoc

------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
adyoung@win.bright.net

Dec 1st, 1999, 05:17 AM
i forgot where i got this but it works
and you can modify it for what you need:

This tip uses the registry to get the current printer name. Make a new project and add a form. To the form add a command button. Copy the following code into the form's General Declarations procedure:

'Declarations
Private Declare Function RegOpenKeyEx Lib "advapi32" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal dwReserved As Long, ByVal samDesired As Long, phkResult As Long) As Long
Private Declare Function RegQueryValueEx Lib "advapi32" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName$, ByVal lpdwReserved As Long, lpdwType As Long, lpData As Any, lpcbData As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32" (ByVal hKey As Long) As Long

Const HKEY_CURRENT_CONFIG As Long = &H80000005

Function RegGetString$(hInKey As Long, ByVal subkey$, ByVal valname$)

'Needed declarations
Dim RetVal$, hSubKey As Long, dwType As Long, SZ As Long
Dim R As Long

RetVal$ = ""

Const KEY_ALL_ACCESS As Long = &HF0063
Const ERROR_SUCCESS As Long = 0
Const REG_SZ As Long = 1

'Open the key
R = RegOpenKeyEx(hInKey, subkey$, 0, KEY_ALL_ACCESS, hSubKey)

If R <> ERROR_SUCCESS Then GoTo Quit_Now

SZ = 256: v$ = String$(SZ, 0)
R = RegQueryValueEx(hSubKey, valname$, 0, dwType, ByVal v$, SZ)

If R = ERROR_SUCCESS And dwType = REG_SZ Then
RetVal$ = Left$(v$, SZ - 1)
Else
RetVal$ = "--Not String--"
End If

If hInKey = 0 Then
R = RegCloseKey(hSubKey)
End If

Quit_Now:
RegGetString$ = RetVal$
End Function

Private Sub Command1_Click()
Dim GetCurrPrinter As String

GetCurrPrinter = RegGetString$(HKEY_CURRENT_CONFIG, "System\CurrentControlSet\Control\Print\Printers", "Default")
MsgBox GetCurrPrinter
End Sub

OlgaV
Dec 1st, 1999, 08:29 PM
Aaron,
Here's what I need to do:
I have several network printers attached to the computer. I need to use AcrobatPDFWriter printer. So, I need to figure out which printer is currently set as default, put it into a variable, do printing using AcrobatPDFWriter printer, and then set printer back the way it was.
Also, when I'm done printing, the little print icon stays in my status bar with status "Paused". I need it out of there!

Larryn,
Thanks for your code. Unfortunately, it doesn't work for me. When I get to
"Quit_Now:", RetVal$ is empty.

Aaron Young
Dec 2nd, 1999, 11:18 AM
Here's a Function I wrote which will search the Printers for the specified Devicename of the Printer you want to use.
If it's found the Function will return the Current Printer Devicename and Change to the Specified Printer.

To Restore the Original/Default Printer, just call the Function again with the Initially returned Devicename, eg.

Private Sub Command1_Click()
Dim sDefault As String
'Select New Printer
sDefault = SelectPrinter("Generic / Text Only")
If Len(sDefault) Then
'Do Print Here
'Select Original Printer
Call SelectPrinter(sDefault)
Else
'Printer Not Found
MsgBox "Printer not Found"
End If
End Sub

Private Function SelectPrinter(ByVal sDeviceName As String) As String
'Enumerates the Printers looking for the specified
'Devicename, if found, returns the Current Printer Devicename
'Prior to changing Printers.
Dim oPRN As Printer
For Each oPRN In Printers
If oPRN.DeviceName = sDeviceName Then
SelectPrinter = Printer.DeviceName
Set Printer = oPRN
Exit For
End If
Next
End Function



------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
adyoung@win.bright.net

Keithuk
Sep 2nd, 2010, 07:09 PM
If R <> ERROR_SUCCESS Then GoTo Quit_Now
What is this supposed to be?



Private Sub Command1_Click()
Dim GetCurrPrinter As String

GetCurrPrinter = RegGetString$(HKEY_CURRENT_CONFIG, "System\CurrentControlSet\Control\Print\Printers", "Default")
MsgBox GetCurrPrinter
End Sub
I know this is an old post but I've been after the default printer from the registry for a long time. I've searched on here but I haven't found the answer. The above code has errors he obviously doesn't use Option Explicit.

That registry path will find the printer on a Win9x/ME system I've used it for years but it won't find it on a WinNT system.

I know MsgBox Printer.DeviceName will give the printer and computer but I just need the printer name.

Can anyone help me find the default printer on a WinNT system?

As well as the printer I need the graphics/video card from the registry as well. The registry remembers all graphics cards that have been fitted. I changed the card on my old computer and the old card and new card were both in there. ;)

westconn1
Sep 3rd, 2010, 04:58 AM
getdefaultprinter API
works for w2000 xp
does not work for 9x

or if you really want to do in registry
HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows\device

WMI could be a good option for video card

Keithuk
Sep 3rd, 2010, 06:19 AM
WMI could be a good option for video card
Cheers westconn but WMI doesn't work on Win9x/ME. With Win9x/ME you can normally get it from the system.ini but sometimes it isn't always true. ;)