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
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.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.