Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

How to install/uninstall Printer Driver programatically ?

Total Hit ( 5609)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


This article will show you how to install/uninstall Printer Driver without any user interaction.

Step-By-Step Example

- Create a standard exe project
- Copy and Paster the following code in form code window
- Make sure you modify various parameter according to your requirement.

Click here to copy the following block
Option Explicit
'******************************************************
' Adding Printer Drivers
'******************************************************
Private Type DRIVER_INFO_4
  cVersion As Long
  pName As String
  pEnvironment As String
  pDriverPath As String
  pDataFile As String
  pConfigFile As String
  pHelpFile As String
  pDependentFiles As String
  pMonitorName As String
  pDefaultDataType As String
  pszzPreviousNames As String
End Type


Private Declare Function AddPrinterDriver Lib "winspool.drv" Alias "AddPrinterDriverA" _
    (ByVal pName As String, ByVal Level As Long, pDriverInfo As Any) As Long

Private Declare Function DeletePrinterDriver Lib "winspool.drv" Alias "DeletePrinterDriverA" ( _
    ByVal pName As String, _
    ByVal pEnvironment As String, _
    ByVal pDriverName As String) As Long

Function InstallDriver() As Boolean
  Dim DI4 As DRIVER_INFO_4
  Dim DriverPath As String
  Dim result As Long

  DriverPath = "C:\WINDOWS\system32\spool\drivers\w32x86\3\"
  With DI4
    .cVersion = 3  '0 Driver for Windows 95/98/Me.
    '1 Driver for Windows NT 3.51.
    '2 Driver for Windows NT 4.0.
    '3 Driver for Windows 2000/XP.
    .pName = "HP LaserJet 4V"
    .pEnvironment = vbNullString
    .pDriverPath = DriverPath & "UNIDRV.DLL"  '//Main Driver file for printer
    .pDataFile = DriverPath & "HPLJ4V.GPD"
    .pConfigFile = DriverPath & "UNIDRVUI.DLL"
    .pHelpFile = DriverPath & "UNIDRV.HLP"
    .pDependentFiles = DriverPath & "PCL5ERES.DLL" & vbNullString & _
        DriverPath & "TTFSUB.GPD" & vbNullString & _
        DriverPath & "UNIRES.DLL" & vbNullString & _
        DriverPath & "STDNAMES.GPD"
    .pMonitorName = "PJL Language Monitor"
    .pDefaultDataType = vbNullString
    .pszzPreviousNames = vbNullString
  End With

  result = AddPrinterDriver(vbNullString, 4, DI4)
End Function

Public Function UninstallDriver(Drivername As String) As Boolean
  On Local Error Resume Next
  Dim res As Long
  res = DeletePrinterDriver(vbNullString, vbNullString, Drivername)
  If res = 0 Then
    UninstallDriver = False
  Else
    UninstallDriver = True
  End If
End Function

Private Sub Form_Load()
  MsgBox "Driver Install: " & InstallDriver
  MsgBox "Driver UnInstall: " & UninstallDriver("HP LaserJet 4V")
End Sub

- Press F5 to run the demo


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.