Page 1 of 1 1
Topic Options
#143996 - 2005-07-21 02:54 AM ComputerInGroup() Working on XP, not on 2000
Skip Offline
Fresh Scripter

Registered: 2005-07-01
Posts: 41
Your help is greatly appreciated. This is my 3rd time posting here, first on this subject and so far have had great success. If I have posted to the incorrect board, please remove or delete. I am a NOOB, but I am really trying hard to get this.

I want to map printers to map for any user that sits sits down at a PC. So, I created 6 or 7 Universal Security Groups and placed each of our PC's into one of these groups. No PC is in 2 groups. We are a child Domain in a Multi-Domain Forest. Domain name is PHI. Howard and Radimus' UDF is working well on the XP Pro PC's, but I can not get it to work on the 2000 boxes. Below is both the mapprinters.kix script and the UDF, being used.

The W2k boxes I have been testing are members of the "ph_prt_medical_area" group. Our AD environment is all 2003 server.
I am not sure if I need to edit the UDF or not. If I do, could someone assist in correct syntax?

The printers are not getting installed at all on the 2000 PC's. There are no printers installed on the PC's at all. I can successfully install and set the default printers via KixTart without using the UDF, but that won't work due to PC and printer locations.

Thanks again for your help.
mapprinters.kix
Code:

Break ON
CLS

If @PRODUCTSUITE & 16 RETURN; If this is a terminal server does not execute
EndIf
If @PRODUCTTYPE = "Windows Server 2003" or @PRODUCTTYPE = "Windows Server 2003 Domain Controller" or @PRODUCTTYPE = "Windows Server 2000" or @PRODUCTTYPE = "Windows Server 2000 Domain Controller" RETURN
EndIf

Dim $UDFPATH
$UDFPATH = "\\phi2\netlogon"
CALL $UDFPATH+"\Computeringroup.udf"
;CALL $UDFPATH+"\GetDefaultPrinter.udf"
; Product Types will have to be added for additional operating systems
If @PRODUCTTYPE = "Windows NT Workstation" Or @PRODUCTTYPE = "Windows 2000 Professional" Or @PRODUCTTYPE = "Windows XP Professional"

;Find out what the Default Printer is
$PrinterKey = "HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows"
$PrinterVal = "Device"
$TempString = READVALUE ($PrinterKey, $PrinterVal)

;The Printername is the first part of the registry value
$x = INSTR($TempString,",")
$DefaultPrinter = SUBSTR($TempString,1,$x-1)

If ComputerInGroup('phlax_prt_lafra')=1
If $DefaultPrinter = "\\philaxsrv01\HP LaserJet 5Si MX"
RETURN
ELSE
AddPrinterConnection("\\philaxsrv01\laser1")
? "Added printer connection...."
If SetDefaultPrinter("\\philaxsrv01\HP LaserJet 5Si MX")
? "Default printer was set to \\philaxsrv01\laser1"
RETURN
EndIf
EndIf
EndIf

If ComputerInGroup('ph_prt_confroom_area')=1
If $DefaultPrinter = "\\phi2\SAVIN 2545/2245 RPCS"
RETURN
ELSE
AddPrinterConnection ("\\phi2\copier2") = 0
? "Added printer connection...."
If SetDefaultPrinter ("\\phi2\SAVIN 2545/2245 RPCS") = 0
? "Default printer was set to \\phi2\copier2, Outside Conference Room BLDG 1"
RETURN
EndIf
EndIf
EndIf

If ComputerInGroup('ph_prt_stoploss_area')=1
If $DefaultPrinter = "\\phi2\HP LaserJet 4000 Series PCL 6 #2 on PHI2"
RETURN
ELSE
AddPrinterConnection("\\phi2\hp4000-2")
AddPrinterConnection("\\phi2\copier2")
? "Added printer connection...."
If SetDefaultPrinter("\\phi2\HP LaserJet 4000 Series PCL 6 #2 on PHI2") = 0
? "Default printer was set to \\phi2\hp4000-2, by the Kitchen Area in BLDG 1"
RETURN
EndIf
EndIf
EndIf

If ComputerInGroup('ph_prt_medical_area')=1
If $DefaultPrinter = "\\phi2\HP LaserJet 4000 Series PCL6"
RETURN
Else
AddPrinterConnection("\\phi2\hp4000-1")
AddPrinterConnection("\\phi2\copier1")
? "Added printer connection...."
If SetDefaultPrinter("\\phi2\HP LaserJet 4000 Series PCL6") = 0
? "Default printer was set to \\phi2\hp4000-1, In the Medical Claims Area, BLDG 1"
RETURN
EndIf
EndIf
EndIf

If ComputerInGroup('ph_prt_medical_area2')=1
If $DefaultPrinter = "\\phi2\Gestetner 3235e PCL 6"
RETURN
ELSE
AddPrinterConnection("\\phi2\hp4000-1")
AddPrinterConnection("\\phi2\copier1")
? "Added printer connection...."
If SetDefaultPrinter("\\phi2\Gestetner 3235e PCL 6") = 0
? "Default printer was set to \\phi2\Copier3, In the File Room, BLDG 1"
RETURN
EndIf
EndIf
EndIf

If ComputerInGroup('ph_prt_dental_area')=1
If $DefaultPrinter = "\\phi2\Gestetner 3502 PCL 6"
RETURN
ELSE
AddPrinterConnection("\\phi2\copier3")
AddPrinterConnection("\\phi2\hp4100-1")
? "Added printer connection...."
If SetDefaultPrinter("\\phi2\Gestetner 3502 PCL 6")
? "Default printer was set to \\phi2\copier3, BLDG 2"
RETURN
EndIf
EndIf
EndIf

If ComputerInGroup('ph_prt_enr_area')=1
If $DefaultPrinter = "\\phi2\HP LaserJet 4100 PCL 6"
RETURN
ELSE
AddPrinterConnection("\\phi2\hp4100")
AddPrinterConnection("\\phi2\copier3")
? "Added printer connection...."
If SetDefaultPrinter("\\phi2\HP LaserJet 4100 PCL 6")
? "Default printer was set to \\phi2\hp4100, BLDG 2"
RETURN
EndIf
EndIf
EndIf

If ComputerInGroup('ph_prt_itdept_area')=1
If $DefaultPrinter = "\\phi2\HP LaserJet 4050 Series PCL 6"
RETURN
ELSE
AddPrinterConnection("\\phi2\hp4050-1")
AddPrinterConnection("\\phi2\copier2")
? "Added printer connection...."
If SetDefaultPrinter("\\phi2\HP LaserJet 4050 Series PCL 6")
? "Default printer was set to \\phi2\hp4050-1"
RETURN
EndIf
EndIf
EndIf
RETURN



Computeringroup.udf
Code:


Function ComputerInGroup($group,optional $Domain)
Dim $oGrp
if not $domain $domain=@domain endif
$oGrp = GetObject("WinNT://" + $domain + "/" + $group + ",group" )
if @error exit 1 endif if
$oGrp.IsMember("WinNT://" + $domain + "/" + @wksta + "$$" )
$ComputerInGroup=1
else
$ComputerInGroup=0
endif
endfunction

_________________________
-sphilip

Top
#143997 - 2005-07-21 04:34 AM Re: ComputerInGroup() Working on XP, not on 2000
Skip Offline
Fresh Scripter

Registered: 2005-07-01
Posts: 41
Thank you for moving this post. I am sorry for not posting it to the correct forum.
_________________________
-sphilip

Top
#143998 - 2005-07-21 05:24 PM Re: ComputerInGroup() Working on XP, not on 2000
Skip Offline
Fresh Scripter

Registered: 2005-07-01
Posts: 41
Does anyone have any insight to this request? If it is to long of a script, I can trim to just contain the portion's I believe are not working correctly. Let me know if I should edit this one or start a new post with the chopped down version. Many of the lines in the script simply repeat themselves due to the different locations of groups.
_________________________
-sphilip

Top
#143999 - 2005-07-21 05:30 PM Re: ComputerInGroup() Working on XP, not on 2000
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Totally a guess on my part but since this is not ADSI code I doubt it supports UNIVERSAL groups. You could try using Global groups and see if it works maybe.
 

Top
#144000 - 2005-07-22 01:17 AM Re: ComputerInGroup() Working on XP, not on 2000
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
The WinNT:// provider does not support Universal groups from what I know. I believe that the ComputerInGroup() wiill need to be replaced with code that uses the LDAP:// provider. Unfortunately, I do not have time to provide a complete solution.


I do think that you could use TranslateName() to get the DN of the group and then rewrite ComputerInGroup() to use the LDAP provider.


Edited by Howard Bullock (2005-07-22 01:18 AM)
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#144001 - 2005-07-22 03:40 PM Re: ComputerInGroup() Working on XP, not on 2000
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Here is one that works with Universal Groups and AD. You must know the distinguishedName of the group.

fnADComputerInGroup("CN=TestGroup,OU=Groups,DC=my,DC=domain,DC=com")

Function fnADComputerInGroup($sGroupDN)
Dim $objSys,$objCom,$aMemberOf,$sMemberOf
$objSys = CreateObject("ADSystemInfo")
$objCom = GetObject("LDAP://"+$objSys.ComputerName)
$aMemberOf = $objCom.GetEx("memberOf")
For Each $sMemberOf in $aMemberOf
If $sMemberOf = $sGroupDN
$fnADComputerInGroup = NOT 0
Exit
EndIf
Next
$fnADComputerInGroup = NOT 1
EndFunction

Top
#144002 - 2005-07-22 04:06 PM Re: ComputerInGroup() Working on XP, not on 2000
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Here is a version that does not require you to know the distinguishedName of the group...

fnADComputerInGroup("TestGroup")

Function fnADComputerInGroup($sGroupDN)
Dim $objSys,$objCom,$aMemberOf,$sMemberOf
$objSys = CreateObject("ADSystemInfo")
$objCom = GetObject("LDAP://"+$objSys.ComputerName)
$aMemberOf = $objCom.GetEx("memberOf")
For Each $sMemberOf in $aMemberOf
If InStr($sMemberOf,"CN="+$sGroupDN+",")
$fnADComputerInGroup = NOT 0
Exit
EndIf
Next
$fnADComputerInGroup = NOT 1
EndFunction

Top
#144003 - 2005-07-22 05:13 PM Re: ComputerInGroup() Working on XP, not on 2000
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
Instead of enumerating the groups, i think you can use the IsMember() function

getobject(adsPathOfGroup).IsMember(adsPathOfComputer)

Top
#144004 - 2005-07-22 05:36 PM Re: ComputerInGroup() Working on XP, not on 2000
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
True, but then it is required to know the distinguishedName of the group.
Top
#144005 - 2005-07-22 06:01 PM Re: ComputerInGroup() Working on XP, not on 2000
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
Yes you would, but somebody wrote a really nice UDF to get that information easily. now who was that...
Top
#144006 - 2005-07-22 07:03 PM Re: ComputerInGroup() Working on XP, not on 2000
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
A SysyAdmin would be expected to know the DN.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#144007 - 2005-07-22 07:16 PM Re: ComputerInGroup() Working on XP, not on 2000
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Quote:

A SysyAdmin would be expected to know the DN.




Funny, I never thought of you as being an optimist.

Top
#144008 - 2005-07-22 07:23 PM Re: ComputerInGroup() Working on XP, not on 2000
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
I did not say that sysyadmins WOULD know the DN, only that they SHOULD know it.
There is a very large gap between would and should.
I have high expectations of sysadmins and low regard for sysyadmins.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#144009 - 2005-07-22 07:46 PM Re: ComputerInGroup() Working on XP, not on 2000
Skip Offline
Fresh Scripter

Registered: 2005-07-01
Posts: 41
Chris if you are ever in Southern California, look me up. First round on me. The second code you posted is what I am using, and it is working great. I didn't have to change anything in your UDF, it was perfect!! For obvious reasons, I did have to change all the ComputerInGroup() to fnADComputerInGroup in my mapprinters.kix script, and rename the udf to fnADComputerInGroup.udf. But it is working great. If you want me to post the finished code. I would be happy to. I need to modify it a bit first, based on feedback from others in previous posts I did. That should be done within a day. But the code is working perfectly. Thank you!!!

P.S. I like the idea of not having to know the distinguished name of the group. Generic is better, no sense hard coding this type of information if you can get away with it. Makes reorganizations much easier.
Quote:

(CN=TestGroup,OU=Groups,DC=my,DC=domain,DC=com)




Thanks again to everyone who helped out on this one. This is a real time saver for our setup. We have a high turnover rate, and a bunch of ninny's that keep wanting to move desks. Like one cubicle is better than another.
_________________________
-sphilip

Top
#144010 - 2005-07-22 07:53 PM Re: ComputerInGroup() Working on XP, not on 2000
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
You could also use the newly created fnInGroupAD() to determine (universal) group membership for the current user or computer.
Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 837 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.063 seconds in which 0.022 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org