Select Default Printer - From Api

A veces es necesario saber cual es la impresora predeterminada, para enviar la
impresi?n. Con el uso de este c?digo podr?s enviar a la impresora por default
o tomar esta para alg?n uso en particular.

Sometimes it is necessary to know which is the predetermined printer, to send
the impression. With the use of this code will be able to send to the printer
by default or to take this for some I use in particular.
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
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
Declare Function RegCloseKey Lib "advapi32" (Byval hKey As Long) As Long

Sub Click(Source As Button)
Dim PName As String
Dim WorkSpace As New NotesUIWorkSpace
Dim UIDoc As NotesUIDocument
Dim Doc As NotesDocument
Set UIDoc = WorkSpace.CurrentDocument
Set Doc = UIDoc.Document
Doc.txtPrinterDefault = GetCurrPrinter()
End Sub

Function GetCurrPrinter() As String
Const HKEY_CURRENT_CONFIG = &H80000005
GetCurrPrinter = RegGetString$(HKEY_CURRENT_CONFIG,
"System\CurrentControlSet\Control\Print\Printers", "Default")
End Function

Function RegGetString$(hInKey As Long, Byval subkey$, Byval valname$)
Dim RetVal$, hSubKey As Long, dwType As Long, SZ As Long
Dim R As Long

RetVal$ = ""
Const REG_SZ = 1

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)
RetVal$ = "--Not String--"
End If
If hInKey = 0 Then R = RegCloseKey(hSubKey)
RegGetString$ = RetVal$
End Function

This was first published in November 2000

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.