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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding printers via Org Unit 1

Status
Not open for further replies.

Popsea

MIS
Jun 24, 2002
29
US
I can add printers via an Active Directory group. That is no problem. However, is it possible to determine what org unit a user is in and add a printer based off of that?
 
You can use this as your guideline:

Code:
option explicit
Dim WSHNetwork, ADSysInfo, strCurrentUser, errCode

Set WSHNetwork = CreateObject("WScript.Network")
Set ADSysInfo = CreateObject("ADSystemInfo") 'Returns the Distinguished Name of the current User
strCurrentUser = ADSysInfo.UserName)

If instr (strCurrentUser, "OU1") <> 0 Then
	errCode = AddPrinter (\\Printserver\Printer1)
elseif instr (strCurrentUser, "OU2") <> 0 Then
	errCode = AddPrinter (\\Printserver\Printer2)
EndIf

Function AddPrinter (ByVal strPrinterUNC)
	'Description: Mapps a the given printer
	'Returns: a string with the result...
	Dim NetPrinter : Set NetPrinter = CreateObject("WScript.Network")
	On Error Resume Next
	Err.Number = 0
	NetPrinter.AddWindowsPrinterConnection strPrinterUNC
	Select Case Err.number
		Case 0
			AddPrinter = "Printer Connected..."
		Case -2147023095
			AddPrinter = vbcrlf & "ERROR - The network name cannot be found (Mistyped Server, or Printer name)"
		Case Else
			AddPrinter = vbcrlf & "ERROR While connecting Printer. " & Err.Number & " - " & Err.Description
	End Select
	NetPrinter.SetDefaultPrinter strPrinterUNC
	On Error goto 0
	Set NetPrinter = Nothing
End Function

Please tell me if I'm wrong I like to learn from my mistakes...
_____________________________________
Feed a man a fish and feed him for a day.
Teach a man to fish and feed him for a lifetime...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top