Jump to content

Recommended Posts

Posted

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.

Posted

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 :)

Posted

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 :)

Posted
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
Posted

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

Posted

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.

Posted
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.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...