Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Logon script to remove printer drivers

Posted on 2010-09-09
Medium Priority
Last Modified: 2012-05-10
I'm having some trouble with getting a logon script to work properly. The script is to install a new printer on everyone’s PCs. I want the script to remove a network printer connection, stop & restart the printer spooler, remove the old printer drivers then re-connect the new network printer. I have created 2 batch files that are called from logon.vbs when users logon.
These commands work OK but only when the user logging in has admin rights?
Can someone please help with this?
High points because answer needed in a hurry!
Thanks in advance

@echo off
REM delete old printer connection(s)
rundll32 printui.dll,PrintUIEntry /dn /n\\ABCdc01\ABCprt01 /q
REM stop & start print spooler
net stop spooler
net start spooler
REM delete old printer driver(s)
rundll32 printui.dll,PrintUIEntry /dd /c\\%ComputerName% /m "PCL6 Driver for Universal Print" /h "Intel" /v "Windows 2000 or XP" /q
rundll32 printui.dll,PrintUIEntry /dd /c\\%ComputerName% /m "RICOH Aficio 3045 RPCS" /h "Intel" /v "Windows 2000 or XP" /q
rundll32 printui.dll,PrintUIEntry /dd /c\\%ComputerName% /m "RICOH Aficio MP C2000 RPCS" /h "Intel" /v "Windows 2000 or XP" /q
rundll32 printui.dll,PrintUIEntry /dd /c\\%ComputerName% /m "RICOH Aficio MP C4500 RPCS" /h "Intel" /v "Windows 2000 or XP" /q

REM connect network printer
Start /wait rundll32 printui.dll,PrintUIEntry /in /n\\ABCDC01\ABCPRT01 /q
REM set default printer
rundll32 printui.dll,PrintUIEntry /y /n\\ABCDC01\ABCPRT01 /q

' Connect ABC Printers
If IsMember("ABCUSER") then
      showstat("Connecting ABC Printers...Please Wait...")
' Remove old printers (temp)
      objShell.Run("%LOGONSERVER%\NETLOGON\delete_ABC_printers.bat"), 1, True

' Connect printers
objShell.Run("%LOGONSERVER%\NETLOGON\connect_ABC_printers.bat"), 1, True

End If
Question by:dee_nz
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
LVL 17

Accepted Solution

Tony Massa earned 2000 total points
ID: 33643312
You can't install new printer drivers unless the user is a member of the "Power Users" or "Administrators" group on the local computer and the "Load and Unload Device Driver" rights are left as the default.

Here's a sample VBScript that will remove and readd a specified network printer
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
  & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set WshNetwork = CreateObject("WScript.Network")

Set colInstalledPrinters =  objWMIService.ExecQuery _
  ("Select * from Win32_Printer where Network = TRUE")

For Each objPrinter in colInstalledPrinters
  If objPrinter.Name = "\\Printserver\Sales" Then
    WshNetwork.RemoveWindowsPrinterConnection objPrinter.Name
    WshNetwork.AddWindowsPrinterConnection objPrinter.Name
    If objPrinter.Default = "True" Then
      WshNetwork.SetDefaultPrinter objPrinter.Name
    End If
  End If

Open in new window


Author Comment

ID: 33659695
Hi, Thanks for your help.
All domain users are "power users" this is what I cant get to work in our logon script.
Can you see what is wrong with it?
If IsMember("ABCUSER") Then
	showstat("Checking Printers...Please Wait...")
	' Remove Printer(s)
	WshNetwork.RemovePrinterConnection "\\acbdc01\abcprt01"
	' Re-connect Printer(s)
         WshNetwork.AddWindowsPrinterConnection "\\abcdc01\abcprt01"
	' Set default printer
	WshNetwork.SetDefaultPrinter "\\abcdc01\abcprt01"
End If

Open in new window

LVL 17

Expert Comment

by:Tony Massa
ID: 33661785
Is there an event logged in either the SYSTEM or APPLICATION event logs?  What about the script itself?  Does it generate an error?

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.


Author Comment

ID: 33721680
Hi, Thanks for your comments. I gave up trying to get the logon script to work and went back to using printui.dll,PrintUIEntry commands in a batch file called from logon.vbs. In the end there were 2 things wrong with my original printer setup batch file.
1. the command syntax was wrong, I had some spaces missing and needed some speech marks " in the right places!
2. tmassa99 was correct users also did not have the correct permissions to change the printer drivers.
There are a few ways to fix this but in the end I created an Active Directory group called "PrinterInstall" that was a member of the local PCs administrators group and so had rights to run the printer batch file.
The logon script would only call printers.bat if the user was in the PrinterInstall group. Then I temporarily put users in the group, printers installed OK after a day or 2 then I removed them from the group.
Seemed to work OK ;)
Thanks for your help
@echo off

:: Delete Network Printer(s) 
start /wait RunDll32 printui.dll,PrintUIEntry /dn /q /n "\\abcdc01\abcprt01"

:: Stop & Start Print Spooler 
start /wait net stop spooler
start /wait net start spooler

:: Delete Old Printer Driver(s) 
start /wait rundll32 printui.dll,PrintUIEntry /dd /c\\%ComputerName% /m "PCL6 Driver for Universal Print" /h "Intel" /v "Windows 2000 or XP" /q
start /wait rundll32 printui.dll,PrintUIEntry /dd /c\\%ComputerName% /m "RICOH Aficio 3045 RPCS" /h "Intel" /v "Windows 2000 or XP" /q
start /wait rundll32 printui.dll,PrintUIEntry /dd /c\\%ComputerName% /m "RICOH Aficio MP C2000 RPCS" /h "Intel" /v "Windows 2000 or XP" /q
start /wait rundll32 printui.dll,PrintUIEntry /dd /c\\%ComputerName% /m "RICOH Aficio MP C4500 RPCS" /h "Intel" /v "Windows 2000 or XP" /q
start /wait rundll32 printui.dll,PrintUIEntry /dd /c\\%ComputerName% /m "HP LaserJet 4050 Series PCL" /h "Intel" /v "Windows 2000 or XP" /q
start /wait rundll32 printui.dll,PrintUIEntry /dd /c\\%ComputerName% /m "RICOH Aficio MP 5001 PCL 6" /h "Intel" /v "Windows 2000 or XP" /q
start /wait rundll32 printui.dll,PrintUIEntry /dd /c\\%ComputerName% /m "RICOH Aficio MP C5000 PCL 6" /h "Intel" /v "Windows 2000 or XP" /q
start /wait rundll32 printui.dll,PrintUIEntry /dd /c\\%ComputerName% /m "RICOH Aficio 3224C RPCS" /h "Intel" /v "Windows 2000 or XP" /q

:: Connect Printer(s) 
start /wait RunDll32 printui.dll,PrintUIEntry /in /q /n "\\abcdc01\abcprt01"

:: Set default printer 
start /wait rundll32 printui.dll,PrintUIEntry /y /q /n "\\abcdc01\abcprt01"

Open in new window


Author Comment

ID: 33721688
Here is the logon.vbs printer section

' **********************************************************
' ***        Connect Network Printers                       ***
' **********************************************************
 If IsMember("InstallABCPrinters") Then
      showstat("Checking ABC Printers...Please Wait...")
      Set objShell = WScript.CreateObject("WScript.Shell")
      objShell.Run("%LOGONSERVER%\NETLOGON\abc_printers.bat"), 1, True
 End If

Author Closing Comment

ID: 33721695
Although I still couldnt get the VB script to work this info led me to find the solution because users did not have the correct rights to change printers. Thanks for the quick reply too ;)

Featured Post

What Is Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've always wanted to allow a user to have a printer no matter where they login. The steps below will show you how to achieve just that. In this Article I'll show how to deploy printers automatically with group policy and then using security fil…
This script will sweep a range of IP addresses (class c only, and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question