#143996 - 2005-07-21 02:54 AM
ComputerInGroup() Working on XP, not on 2000
|
Skip
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
|
|
|
|
#144000 - 2005-07-22 01:17 AM
Re: ComputerInGroup() Working on XP, not on 2000
|
Howard Bullock
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)
|
|
Top
|
|
|
|
#144001 - 2005-07-22 03:40 PM
Re: ComputerInGroup() Working on XP, not on 2000
|
Chris S.
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.
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
|
|
|
|
#144005 - 2005-07-22 06:01 PM
Re: ComputerInGroup() Working on XP, not on 2000
|
maciep
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
|
|
|
|
#144007 - 2005-07-22 07:16 PM
Re: ComputerInGroup() Working on XP, not on 2000
|
Chris S.
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
|
|
|
|
#144009 - 2005-07-22 07:46 PM
Re: ComputerInGroup() Working on XP, not on 2000
|
Skip
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.
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
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 847 anonymous users online.
|
|
|