Solved

Logon script to remove printer drivers

Posted on 2010-09-09
6
2,430 Views
Last Modified: 2012-05-10
Hi,
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
-D

delete_abc_printers.bat
@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

connect_abc_printers.bat
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

logon.vbs
' 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
0
Comment
Question by:dee_nz
  • 4
  • 2
6 Comments
 
LVL 17

Accepted Solution

by:
Tony Massa earned 500 total points
Comment Utility
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.
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/windows_security_default_settings.mspx?mfr=true

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

Next

Open in new window

0
 
LVL 4

Author Comment

by:dee_nz
Comment Utility
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?
Thanks
-D
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

0
 
LVL 17

Expert Comment

by:Tony Massa
Comment Utility
Is there an event logged in either the SYSTEM or APPLICATION event logs?  What about the script itself?  Does it generate an error?
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 4

Author Comment

by:dee_nz
Comment Utility
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
-D
@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

0
 
LVL 4

Author Comment

by:dee_nz
Comment Utility
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
0
 
LVL 4

Author Closing Comment

by:dee_nz
Comment Utility
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 ;)
-D
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Scenerio: You have a server running Server 2003 and have applied a retail pack of Terminal Server Licenses.  You want to change servers or your server has crashed and you need to reapply the Terminal Server Licenses. When you enter the 16-digit lic…
A quick step-by-step overview of installing and configuring Carbonite Server Backup.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

763 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now