Solved

map printers by group

Posted on 2006-10-29
14
350 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
Superior storage. Superior surveillance.

WD Purple drives are built for 24/7, always-on, high-definition security systems. With support for up to 8 hard drives and 32 cameras, WD Purple drives are optimized for surveillance.

 
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 camera licenses with purchase of My Cloud NAS

Milestone Arcus software is compatible with thousands of industry-leading cameras for added flexibility. Upon installation on your My Cloud NAS, you will receive two (2) camera licenses already enabled in the software. And for a limited time, get additional camera licenses FREE.

Question has a verified solution.

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

ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
When you try to share a printer , you may receive one of the following error messages. Error message when you use the Add Printer Wizard to share a printer: Windows could not share your printer. Operation could not be completed (Error 0x000006…
After creating this article (http://www.experts-exchange.com/articles/23699/Setup-Mikrotik-routers-with-OSPF.html), I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…
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…

932 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

11 Experts available now in Live!

Get 1:1 Help Now