• 0

VBS Adding printers Depending on AD group.


Question

Hi,

I have been looking for a vbs that will add certain printers dependant on what group a user is in within active directory.

this would then need to be launched from the logon script.

I have found this code below but would like to know how to change it so it looks for multiple OU's within Active Directory and install multiple printers for some users.

Thanks for any help on this.

Dim objNetwork
Set objNetwork = CreateObject("WScript.Network")

Dim objWinntComp
Set objWinntComp = GetObject("WinNT://" & objNetwork.UserDomain & "/" & objNetwork.ComputerName & ",computer")
'MsgBox "WinNT://" & objNetwork.UserDomain & "/" & objNetwork.ComputerName & ",computer"

Dim strGroupToCheck
Dim strPrinter
strPrinter = "\\server\IT_Printer"
strGroupToCheck = "IT_Printer"

If IsMemberOfGroup(objNetwork.UserDomain, objWinntComp, strGroupToCheck) = True Then
	MsgBox "You are a member of " & strGroupToCheck & VbCrLf & "Mapping printer: " & strPrinter
	objNetwork.AddWindowsPrinterConnection strPrinter
ElseIf IsMemberOfGroup(objNetwork.UserDomain, objWinntComp, strGroupToCheck) = False Then
	MsgBox "You are NOT a member of " & strGroupToCheck
	WScript.Quit
ElseIf IsMemberOfGroup(objNetwork.UserDomain, objWinntComp, strGroupToCheck) = "Error" Then
	MsgBox "There was no group found called " & strGroupToCheck
	WScript.Quit
End If	

Function IsMemberOfGroup(strUserDomain, objComp, strGroup) 'the user is a member of a specified group
	IsMemberOfGroup = False
	Dim objGroup
	On Error Resume Next
	Set objGroup = GetObject("WinNT://" & strUserDomain & "/" & strGroup & ",group")
	If Err.Number Then
		IsMemberOfGroup = "Error"
	Else
		IsMemberOfGroup = objGroup.IsMember(objComp.ADsPath & "$")
	End If
End Function

Edited by SoulDevil

0 answers to this question

Recommended Posts

There have been no answers to this question yet

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.