?
Solved

map printers by group

Posted on 2006-10-29
14
Medium Priority
?
366 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 1000 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
Connect further...control easier

With the ATEN CE624, you can now enjoy a high-quality visual experience powered by HDBaseT technology and the convenience of a single Cat6 cable to transmit uncompressed video with zero latency and multi-streaming for dual-view applications where remote access is required.

 

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 1000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Short answer to this question: there is no effective WiFi manager in iOS devices as seen in Windows WiFi or Macbook OSx WiFi management, but this article will try and provide some amicable solutions to better suite your needs.
During and after that shift to cloud, one area that still poses a struggle for many organizations is what to do with their department file shares.
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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Suggested Courses

801 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