Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing to the network printer 1

Status
Not open for further replies.

Vexaxix

Programmer
Sep 24, 2003
13
CA
From within a extra macro, how can i determine the users default network printer name?

 
Save VB Code below as header file:

Default Printer.ebh

Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" _
(Byval hKey As Long, Byval lpSubKey As String, Byval ulOptions As Long, _
Byval samDesired As Long, phkResult As Long) As Long

Declare Function RegCloseKey Lib "advapi32.dll" (Byval hKey As Long) As Long

Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" _
(Byval hKey As Long, Byval lpValueName As String, Byval lpReserved As Long, _
lpType As Long, Byval lpData As String, lpcbData As Integer) As Long

'-- Constant Definitions for WIN32API
Const KEY_QUERY_VALUE = &H1
Const HKEY_CURRENT_USER = &H80000001
Const ERROR_SUCCESS = 0&


Function GetDftPrt() As String
KeyName$ = "Software\Microsoft\Windows NT\CurrentVersion\Windows"
RetCd = RegOpenKeyEx(HKEY_CURRENT_USER, KeyName$, 0, KEY_QUERY_VALUE, keyhandle)
If RetCd = ERROR_SUCCESS Then
Dim Ret_Type As Long
Dim lpFileName As String
Dim lpReturnedString As String*100
Dim retSize%
retSize% = 99
res4& = RegQueryValueEx( keyhandle, "Device", 0, Ret_Type, lpReturnedString, retSize% )
If res4& = ERROR_SUCCESS Then
GetDftPrt = Trim$(Mid( lpReturnedString, 1, InStr ( lpReturnedString, "," )-1))
End If
End If
Call RegCloseKey(keyhandle)
End Function




Example Extra! VB macro retrieving windows default printer.



'$Include: "Default Printer.ebh"
Sub Main
DefaultPrinter = GetDftPrt()
End Sub



This will return the printer name including network path for Windows NT system.

Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top