Solved

map printers by group

Posted on 2006-10-29
14
356 Views
Last Modified: 2010-08-05
This Script below maps printers by user name I would like to know how to map them by group name

Set WshNetwork = CreateObject("WScript.Network")

Select Case WshNetWork.UserName

    Case "Username1"
   
        PrinterPath = "\\Server\Printer1"
        PrinterDriver = "PrinterDriver"
        WshNetwork.AddWindowsPrinterConnection PrinterPath, PrinterDriver

        WshNetwork.SetDefaultPrinter "\\Server\Printer1"
   
    Case "Username2"
   
        PrinterPath = "\\Server\Printer2"
        PrinterDriver = "PrinterDriver"
        WshNetwork.AddWindowsPrinterConnection PrinterPath, PrinterDriver

        WshNetwork.SetDefaultPrinter "\\Server\Printer1"
End Select
0
Comment
Question by:jskfan
[X]
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
  • 6
  • 4
  • 3
  • +1
14 Comments
 
LVL 9

Expert Comment

by:crawfordits
ID: 17831097
if isMember("groupname") then
    commands here
end if
0
 
LVL 20

Accepted Solution

by:
Lazarus earned 250 total points
ID: 17831540
Route printer by OU:

''This script installs printers on XP computers based on computer OU membership
''Simply edit the relevant Sub eg ''A Block Printers'' to reflect your server name and printer sharename
''to add a new location create an extra Case statement for the new OU and a corresponding Sub Print section
''moving a computer to a different OU will refresh the printer connections
''this script will not prevent roaming users from adding their own connection

    Set WshShell = CreateObject("Wscript.Shell")
    Set objAdsSystemInfo = CreateObject("adsysteminfo")
    Set objComputerName = Getobject("LDAP://" & objAdsSystemInfo.ComputerName)
    Set objOU = GetObject(objComputerName.Parent)
    strOU = replace(objOU.Name,"OU=","")
       
    Select Case strOU
        Case "A Block"
             Call Print1()        
                         
        Case "B Block"
             Call Print2()
 
    End Select
 
Sub Print1()

  ''A Block printers
''strRunCmd = "cmd /c rundll32 printui.dll,PrintUIEntry /in /n\\servername\printershare /q"
''wshShell.Run(strRunCmd),showHidden,bWait

strRunCmd = "cmd /c rundll32 printui.dll,PrintUIEntry /in /n\\servername\printershare /q"
wshShell.Run(strRunCmd),showHidden,bWait

''This line sets one of the previously installed printers as the default printer.
''If only 1 printer is configured there is no need to include this line as it will automatically become the default printer.

strRunCmd = "cmd /c rundll32 printui.dll,PrintUIEntry /y /n\\servername\printershare /q"
wshShell.Run(strRunCmd),showHidden,bWait

''This is a sample line to remove a previously installed printer
strRunCmd = "cmd /c rundll32 printui.dll,PrintUIEntry /dn /n\\servername\printershare /q"
wshShell.Run(strRunCmd),showHidden,bWait

End Sub


Sub Print2()

  ''B Block printers
strRunCmd = "cmd /c rundll32 printui.dll,PrintUIEntry /in /n\\servername\printershare /q"
wshShell.Run(strRunCmd),showHidden,bWait

strRunCmd = "cmd /c rundll32 printui.dll,PrintUIEntry /in /n\\servername\printershare /q"
wshShell.Run(strRunCmd),showHidden,bWait

''strRunCmd = "cmd /c rundll32 printui.dll,PrintUIEntry /in /n\\servername\printershare /q"
''wshShell.Run(strRunCmd),showHidden,bWait

''This line sets one of the previously installed printers as the default printer
''strRunCmd = "cmd /c rundll32 printui.dll,PrintUIEntry /y /n\\servername\printershare /q"
''wshShell.Run(strRunCmd),showHidden,bWait

''this is a sample line to remove a previously installed printer
''strRunCmd = "cmd /c rundll32 printui.dll,PrintUIEntry /dn /n\\servername\printershare /q"
''wshShell.Run(strRunCmd),showHidden,bWait

End Sub
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 17831926
Seen that one somewhere before today lazarus :-)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:jskfan
ID: 17833050
<<<<<if isMember("groupname") then
    commands here
end if>>>>>>>>>>>

can you paste the whole code here please?

thanks
0
 
LVL 20

Expert Comment

by:Lazarus
ID: 17834997
Dragon... of course... you gave it out... and it works quite well thank you. I appreciate it and hopefully the questioner will to. ;)
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 17835009
I only found it earlier that day in another EE question :-)
0
 
LVL 20

Expert Comment

by:Lazarus
ID: 17835040
LOL.. yeow.. your as bad as me... I figured out long ago, that what I don't know can be found not much more than a few clicks away... and if not a click somewhere on a page.
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 17835067
but at least we know what we are posting is right... some people just seem to post the contents of google as answers.  Anyway better leave this Q to the question inhand I suppose and I'll shut up!
0
 

Author Comment

by:jskfan
ID: 17871783
I need this:
<<<<<if isMember("groupname") then
    commands here
end if>>>>>>>>>>>
0
 
LVL 20

Assisted Solution

by:Lazarus
Lazarus earned 250 total points
ID: 17873803
You will need to download a file included with the Zero Administration Kit for Windows NT 4.0:

Run the Con2prt.exe Tool from a Login Script
Use the Con2prt.exe tool to connect to a network printer in a Windows NT login script. To do so, follow these steps:

1. Copy the Con2prt.exe tool to the %SystemRoot% folder of the Windows NT-based client computer.  
2. Configure your Windows NT login script to run the Con2prt.exe tool.  

The script below is from oBdA, a very knowledgable EE user.

====8<----[logon.cmd]----
:: *** Delete all mapped printers:
con2prt.exe /f
:: *** Map the printers according to group membership:
ifmember.exe YourDomain\Printer01Group
if not errorlevel 1 goto EndPrinter01Group
con2prt.exe /c \\PrintServer\Printer01
:EndPrinter01Group

ifmember.exe YourDomain\Printer02Group
if not errorlevel 1 goto EndPrinter02Group
con2prt.exe /c \\PrintServer\Printer02
:EndPrinter02Group
====8<----[logon.cmd]----
0
 
LVL 20

Expert Comment

by:Lazarus
ID: 17873807
If you need to add a printer using a direct IP and not a Server Printer you can use this link:
http://support.microsoft.com/?kbid=314486
0
 

Author Comment

by:jskfan
ID: 17951709
I have not tried this script to see if it works.

Actually, I remember seeing a VBScript code that tests if a user is a member of security group then it maps the printer accordingly.

for example : all users which are members of the Accounting group in Active directory, they get mapped to a printer named Accounting when they logon to their computers.

I am trying to find the scripts on the internet but can't find it.
0
 

Author Comment

by:jskfan
ID: 17951786
0
 
LVL 20

Expert Comment

by:Lazarus
ID: 17952775
jskfan, Thats what the vbs script I posted before earlier does.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

If your business is like most, chances are you still need to maintain a fax infrastructure for your staff. It’s hard to believe that a communication technology that was thriving in the mid-80s could still be an essential part of your team’s modern I…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
Viewers will learn how to connect to a wireless network using the network security key. They will also learn how to access the IP address and DNS server for connections that must be done manually. After setting up a router, find the network security…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

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