Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to create a VBS for mapping printers based on username

Status
Not open for further replies.

mhshane

MIS
Dec 12, 2005
130
US
Hello. I have a generic script that maps all printer (15 total) but want to make it more specific so groups only get the printers they need.

I am stuck thinking in terms of "goto" which VBS doesn't support. How would I do the following?

If user group = "HR" then goto Print1
If user group = "RD" then goto Print2
If user group = "Sales" then goto Print3

Print 1
WshNetwork.RemovePrinterConnection "\\HP-FPS\HR_printer", True
WshNetwork.AddWindowsPrinterConnection "\\HP-FPS\HR_printer", True
WshNetwork.RemovePrinterConnection "\\HP-FPS\HR_Copier", True
WshNetwork.AddWindowsPrinterConnection "\\HP-FPS\HR_Copier", True
Goto End

Print2
WshNetwork.RemovePrinterConnection "\\HP-FPS\RD_printer", True
WshNetwork.AddWindowsPrinterConnection "\\HP-FPS\RD_printer", True
WshNetwork.RemovePrinterConnection "\\HP-FPS\RD_Copier", True
WshNetwork.AddWindowsPrinterConnection "\\HP-FPS\RD_Copier", True
Goto End

Print 3
WshNetwork.RemovePrinterConnection "\\HP-FPS\Sales_printer", True
WshNetwork.AddWindowsPrinterConnection "\\HP-FPS\Sales_printer", True
WshNetwork.RemovePrinterConnection "\\HP-FPS\Sales_Copier", True
WshNetwork.AddWindowsPrinterConnection "\\HP-FPS\Sales_Copier", True

End


Thanks for your assitance.
 
I would use a select..case

(pseudo-ish)
Code:
   set WshNetwork = CreateObject("Wscript.Network")
   select (group_name)
      case "HR"
         WshNetwork.RemovePrinterConnection "\\HP-FPS\HR_printer", True
         WshNetwork.AddWindowsPrinterConnection "\\HP-FPS\HR_printer", True
         WshNetwork.RemovePrinterConnection "\\HP-FPS\HR_Copier", True
         WshNetwork.AddWindowsPrinterConnection "\\HP-FPS\HR_Copier", True
      case "RD"
         WshNetwork.RemovePrinterConnection "\\HP-FPS\RD_printer", True
         WshNetwork.AddWindowsPrinterConnection "\\HP-FPS\RD_printer", True
         WshNetwork.RemovePrinterConnection "\\HP-FPS\RD_Copier", True
         WshNetwork.AddWindowsPrinterConnection "\\HP-FPS\RD_Copier", True
      case "Sales" 
         WshNetwork.RemovePrinterConnection "\\HP-FPS\Sales_printer", True
         WshNetwork.AddWindowsPrinterConnection "\\HP-FPS\Sales_printer", True
         WshNetwork.RemovePrinterConnection "\\HP-FPS\Sales_Copier", True
         WshNetwork.AddWindowsPrinterConnection "\\HP-FPS\Sales_Copier", True
      case else
         msgbox "Your group doesn't get any printers..."
   end select

-Geates

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top