Announcement

Collapse
No announcement yet.

Need help to create a script to replace Printer driver

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Need help to create a script to replace Printer driver

    Hi,
    I need help to create a script which replaces one of the the printers driver on the workstations running windows XP.

    thanks
    jay

  • #2
    Re: Need help to create a script to replace Printer driver

    You can try Prndrvr.vbs in a startup script. But I am not sure if the -a (add) switch can also be used to replace existing drivers (?)

    Code:
    ' use prndrvr.vbs
    ' http://technet.microsoft.com/en-us/library/bb490972.aspx
    
    sCommand = "%comspec% /c cscript.exe //Nologo ""%windir%\system32\prndrvr.vbs"""
    
     ' Please note the sDriver Name (that follows with m option) must exactly
     ' math with the driver jou want to install. You can simply open .INF file
     ' to obtain this name or refer to printer documentation.
    sDriver = "HP LaserJet XXXXn"
    sNewDriver = "path\FileName.inf"
    
    ' Stop&Start Spooler service
    ' http://techtasks.com/code/viewbookcode/1409
    On Error resume next
    Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\root\cimv2")
    Set colServiceList = objWMIService.ExecQuery _
            ("Select * from Win32_Service where Name='Spooler'")
      For each objService in colServiceList
         errReturn = objService.StopService()
      Next
    Set colServiceList = objWMIService.ExecQuery _
        ("Select * from Win32_Service where Name='Spooler'")
      For each objService in colServiceList
         errReturn = objService.StartService()
      Next
    
    ' Remove printer driver
    ' sParameters = "-d -m """ & sDriver & """ -v 3 -e ""Windows NT x86"""
    ' sReturn = ExecuteShellProgram(sCommand & space(1) & sParameters)
    
    ' Install printer driver
    sParameters = "-a -m """ & sDriver & """ -v 3 -e ""Windows NT x86"" -i """ & sNewDriver & """"
    sReturn = ExecuteShellProgram(sCommand & space(1) & sParameters)
    
    
    Function ExecuteShellProgram(ByVal sCommand)
     ' http://www.intelliadmin.com/blog/2007/01/how-to-run-external-program-within-vb.html
      Dim poShell 
      Dim poProcess
      Dim iStatus
    
      Set poShell = CreateObject("WScript.Shell")
      Set poProcess = poShell.Exec(sCommand)
    
      'Check to see if we started the process without error
    
      if ((poProcess.ProcessID=0) and (poProcess.Status=1)) then
        Err.Raise vbObjectError,,"Failed executing process"
      end if
    
      'Now loop until the process has terminated, and pull out
      'any console output
    
      Do
        'Get current state of the process
        iStatus = poProcess.Status
        'Did the process terminate?
        if (iStatus <> 0) then
          Exit Do
        end if
        wsh.sleep 1000
      Loop 
    
      'Return the exit code
      ExecuteShellProgram = poProcess.ExitCode
    
    End Function
    \Rems

    This posting is provided "AS IS" with no warranties, and confers no rights.

    __________________

    ** Remember to give credit where credit's due **
    and leave Reputation Points for meaningful posts

    Comment


    • #3
      Re: Need help to create a script to replace Printer driver

      Go to Start - Run - rundll32 printui.dll,PrintUIEntry /?

      This is what i used alot before and there are much possiblities, hopefull this does the trick for you.

      Comment

      Working...
      X