VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Retrieve Current printer name

by Anonymous (267 Submissions)
Category: Windows System Services
Compatability: Visual Basic 4.0 (32-bit)
Difficulty: Unknown Difficulty
Originally Published: Fri 25th December 1998
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Retrieve Current printer name

API Declarations


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

Rate Retrieve Current printer name



Dim PName As String
GetCurrPrinter = RegGetString$(HKEY_CURRENT_CONFIG, "System\CurrentControlSet\Control\Print\Printers", "Default")
PName = GetCurrPrinter

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 KEY_ALL_ACCESS As Long = &HF0063
    Const ERROR_SUCCESS As Long = 0
    Const REG_SZ As Long = 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 - 1)
    Else
        RetVal$ = "--Not String--"
    End If
    If hInKey = 0 Then
        R = RegCloseKey(hSubKey)
    End If
Quit_Now:
        RegGetString$ = RetVal$
End Function

Download this snippet    Add to My Saved Code

Retrieve Current printer name Comments

No comments have been posted about Retrieve Current printer name. Why not be the first to post a comment about Retrieve Current printer name.

Post your comment

Subject:
Message:
0/1000 characters