Solved

map printers by group

Posted on 2006-10-29
14
348 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
  • 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
 

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Website Routing Issue 3 34
Cisco layer 3 ring topology 1 55
VMware NSX version 6.2.2 upgrade 6.2.4 6 51
cisco nexus experiance 2 30
This is an article about my experiences with remote access to my clients (so that I may serve them) and eventually to my home office system via Radmin Remote Control. I have been using remote access for over 10 years and have been improving my metho…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now