|
-
Dec 1st, 1999, 04:12 AM
#1
Thread Starter
Junior Member
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
-
Dec 1st, 1999, 04:29 AM
#2
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
[email protected]
[email protected]
-
Dec 1st, 1999, 06:17 AM
#3
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
-
Dec 1st, 1999, 09:29 PM
#4
Thread Starter
Junior Member
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.
-
Dec 2nd, 1999, 12:18 PM
#5
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.
Code:
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
[email protected]
[email protected]
-
Sep 2nd, 2010, 07:09 PM
#6
Re: Which one is Default Printer?
 Originally Posted by ;7591
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.
Keith
I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.
-
Sep 3rd, 2010, 04:58 AM
#7
Re: Which one is Default Printer?
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
Last edited by westconn1; Sep 3rd, 2010 at 05:16 AM.
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Sep 3rd, 2010, 06:19 AM
#8
Re: Which one is Default Printer?
 Originally Posted by westconn1
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.
Keith
I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|