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
Question
SoulDevil
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 FunctionEdited by SoulDevilLink to comment
Share on other sites
0 answers to this question
Recommended Posts