Solved

Logon script to remove printer drivers

Posted on 2010-09-09
6
2,506 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
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.
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
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?
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
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?
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 4

Author Comment

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

Author Closing Comment

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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

820 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