Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBscript for printers

Status
Not open for further replies.

sapper1

Technical User
Jul 13, 2006
99
US
I am trying to use a VBscript to map printers for a group of computers. As of right now I am trying to run the script via GPO at start up but it is not working. I have even tried copying the script to the start up folder but it still does not run. I can manually run the script and it maps the printers correctly but that is the only way I have been able to get it to work. Any help would be appreciated. Basically I want it to run every time a user logs into one of these computers so they can use these printers.

Set net = WScript.CreateObject("wscript.network")

net.AddWindowsPrinterConnection "\\server\printer1"
net.AddWindowsPrinterConnection "\\server\printer2"

net.SetDefaultPrinter "\\server\printer1"
 
Here is a little nugget we used to use, now everything is handled through GPO but hope this will help you. This script will check the Security group your users belongs to and then if found will map a network printer.. You can add as many security groups and printers under each heading.. Hope this helps you !!
On ERROR RESUME NEXT
Dim objWSHShell 'This is the shell object
Dim objNetwork ' This is our network object
Dim objDomain 'This is our Domain Object
Dim strDomainName 'This is our Domain Name
Dim strUserName 'This is outr user string
Dim objUser 'This is our UserObject
Dim objGroup 'This is our group object
Dim strLowerCaseGroupName 'This String holds the Lower Case group Name

'Create an instance of the Shell
Set objWSHShell = CreateObject("WScript.Shell")
'Create an instance of the Network
Set objNetwork = CreateObject("WScript.Network")

'Automatically find the domain name
Set objDomain = GetObject("LDAP://rootDse")
strDomainName = objDomain.Get("dnsHostName")

'Grab the user name
strUserName = objNetwork.UserName

'Bind to the user object to get user name and check for group memberships later
Set objUser = GetObject("WinNT://" & strDomainName & "/" & strUserName)

'Now check for group memberships and map appropriate drives
For Each objGroup In objUser.Groups
'Get the group name and change it to lowercase
'Note: This can be either Lowercase (LCase) or Uppercase (UCase)
strLowerCaseGroupName = LCase (objGroup.Name)

Select Case strLowerCaseGroupName
'Check for group memberships and take needed action

Case "Claims-Users"

objNetwork.AddWindowsPrinterConnection "\\Server1\PrinterName01", true
objNetwork.AddWindowsPrinterConnection "\\Server1\PrinterName02", true

Case "Service-Users"

objNetwork.AddWindowsPrinterConnection "\\Server1\PrinterName01", True
objNetwork.AddWindowsPrinterConnection "\\Server1\PrinterName02", True
objNetwork.AddWindowsPrinterConnection "\\Server1\PrinterName03", True

Case "Managers"

objNetwork.AddWindowsPrinterConnection "\\Server1\ColorPrinterName01", True
True

End Select
Next
 
I've noticed that GPO application is flaky at best. I would suggest creating logon script from which to run your print configuration code. Specify it under "Logon script" in each user's AD account.

-Geates


"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top