Solved

map printers by group

Posted on 2006-10-29
14
359 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

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 NetCrunch network monitor licenses!

Only on Experts-Exchange: Sign-up for a free-trial and we'll send you your permanent license!

Here is what you get: 30 Nodes | Unlimited Sensors | No Time Restrictions | Absolutely FREE!

Act now. This offer ends July 14, 2017.

Question has a verified solution.

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

Data center, now-a-days, is referred as the home of all the advanced technologies. In-fact, most of the businesses are now establishing their entire organizational structure around the IT capabilities.
If you're not part of the solution, you're part of the problem.   Tips on how to secure IoT devices, even the dumbest ones, so they can't be used as part of a DDoS botnet.  Use PRTG Network Monitor as one of the building blocks, to detect unusual…
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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses

724 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