borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (Passing parameters to crystal report)Next Topic (Printing) New Topic New Poll Post Reply
AndreaVB Forum : Printing : select default printer in VB?
Poster Message
luckyboy
Level: VB Lord

Registered: 05-05-2005
Posts: 160

icon select default printer in VB?

I would like to know how can i open property default printer in VB. And I don want to open by Common Dialog. Because it can not determind forever. For example I need to print with paper A4 not only one time but all the times. What I need is to Open printer like Start Menu ->Settings ->Printers
-> Right Mouse in default printer ->Property ->Printint Preferences. Any one please help me out!
                                                     Thank you for your help.


____________________________
Please help out.

05-07-2005 at 09:17 AM
View Profile Send Email to User Show All Posts | Quote Reply
madkat
Level: Trainee

Registered: 27-09-2005
Posts: 1
icon Re: select default printer in VB?

Include Windows Script Host Object Model in your References, then:

    Dim w As New WshNetwork
    w.SetDefaultPrinter (DeviceName)
    Set w = Nothing

27-09-2005 at 09:29 AM
View Profile Send Email to User Show All Posts | Quote Reply
TJ_01
Level: VB Lord


Registered: 24-08-2005
Posts: 320
icon Re: select default printer in VB?

Would this code helps?

Get the Current Printer Name

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



____________________________
Im JAMES  

28-09-2005 at 02:30 AM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : Printing : select default printer in VB?
Previous Topic (Passing parameters to crystal report)Next Topic (Printing) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder