Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Logon script to remove printer drivers

Posted on 2010-09-09
6
Medium Priority
?
2,719 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 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.
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

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

 
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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying 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

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…
Learn about cloud computing and its benefits for small business owners.
Integration Management Part 2
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

963 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