tomscaper Posted September 14, 2009 Posted September 14, 2009 I have looked at a few posts already on here about adding a printer script which checks the computer name and adds the printer if it is in a particular group. For example Option explicit dim objNetwork, objComputer, ObjPrinter dim strDomain, strComputerName, MyVar Set objNetwork = WScript.CreateObject("Wscript.Network") strDomain = objNetwork.UserDomain strComputerName = objNetwork.ComputerName Set objComputer = GetObject("WinNT://" & strDomain & "/" & strComputerName & ",computer") Set objPrinter = CreateObject("WScript.Network") If isComputerMember("groupname") then ObjPrinter.AddWindowsPrinterConnection "\\server\printer" end If Function IsComputerMember(sGroup) Dim oGroup on error resume next Set oGroup = GetObject("WinNT://" & strDomain & "/" & sGroup & ",group") IsComputerMember = CBool(oGroup.IsMember(objComputer.ADsPath & "$")) Set oGroup = Nothing If not Err.Number = 0 Then 'isComputerMember could not locate group end if on error goto 0 End Function I am looking to add a printer by the username and the groups they are members of but i am not fully sure how i gould go about doign that. Has anyone already done this.
Soulfish Posted September 14, 2009 Posted September 14, 2009 I'm using GPP's to do the same thing. Since rolling them out at the beginning of September it's been great. We're able to target a printer based on a users group membership, their OU, the OU of the computer and a million other different options. If you're running windows server 2008 or have a vista client you can set the policies up on then your good to go with GPPs (http://www.gpoguy.com/Portals/0/Group%20Policy%20Preferences%20Overview.pdf). For XP + 2003 clients you just need to install the client side extensions so they recognise the GPP's and it should all work
tomscaper Posted September 14, 2009 Author Posted September 14, 2009 I have never user GPP's, how would i install this either on the server and client, where woudl i get this for. I am using XP and 2003
Soulfish Posted September 14, 2009 Posted September 14, 2009 Client install is just a microsoft hotfix that needs to be deployed on XP/2003. Unfortunately to manage it you need a vista/2008 machine. Any older then this and the GPMC doesn't have the options to edit the Group Policy Preferences. Have a read of the link above for more info
tomscaper Posted September 14, 2009 Author Posted September 14, 2009 I dont have a vista or 2008 machine to do this one. There must be a way to check if a user is in a certain group. as the scritp above just checks if a machine is in a particular group
tomscaper Posted September 14, 2009 Author Posted September 14, 2009 Found this if anyone is interested. Option explicit dim objNetwork, objUser , ObjPrinter dim strDomain, strUserName Set objNetwork = WScript.CreateObject("Wscript.Network") strDomain = objNetwork.UserDomain strUserName = objNetwork.UserName Set objUser = GetObject("WinNT://" & strDomain & "/" & strUserName & ",user") Set objPrinter = CreateObject("WScript.Network") If IsMember(group) then ObjPrinter.AddWindowsPrinterConnection "\\server\printer" End If Function IsMember(sGroup) Dim oDict, oUser, oGroup If IsEmpty(oDict) Then Set oDict = CreateObject("Scripting.Dictionary") oDict.CompareMode = vbTextCompare For Each oGroup In objUser.Groups oDict.Add oGroup.Name, "-" Next Set oUser = Nothing End If IsMember = CBool(oDict.Exists(sGroup)) End Function
srochford Posted September 14, 2009 Posted September 14, 2009 Looks good. Just a quick point - if you have nested groups then this won't work (eg if you want to map a printer for everyone in year7 but the group year7 is actually made up from groups year7a, year7b, year7c etc) If this is unimportant to you then ignore me completely (most people do :-)) but for anyone else, you could either do things like: If IsMember("year7a") or ismember("year7b") or ismember("year7c") then or you can get into nasty recursive stuff where you take the top level group, enumerate its members and for any groups you find, enumerate them as well. You then have a list of every user in your group and you see if your user is there.
tomscaper Posted September 16, 2009 Author Posted September 16, 2009 Looks good. Just a quick point - if you have nested groups then this won't work (eg if you want to map a printer for everyone in year7 but the group year7 is actually made up from groups year7a, year7b, year7c etc) If this is unimportant to you then ignore me completely (most people do :-)) but for anyone else, you could either do things like: If IsMember("year7a") or ismember("year7b") or ismember("year7c") then or you can get into nasty recursive stuff where you take the top level group, enumerate its members and for any groups you find, enumerate them as well. You then have a list of every user in your group and you see if your user is there. I am not really sure how it works i just found it on the net and pulled it together till it worked for me. Do you know of a better way to do this. one which would incorporate nested groups.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now