Page 1 of 1 1
Topic Options
#195122 - 2009-07-30 08:17 AM Check OU...
vdias Offline
Fresh Scripter

Registered: 2009-07-29
Posts: 8
Loc: Villaverde del Rio, Sevilla, S...
Is the function InOU working on the last kixtart.

I need to map some shares to all users of a OU and it doesn't work...

Just open a command line window with the name of the OU.

The idea is simple.

If user belong to OU then map the drive x:\xxxxxxxx

How can i do that?

Top
#195123 - 2009-07-30 09:25 AM Re: Check OU... [Re: vdias]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
Could go from here:
 Code:
Dim $objSysInfo
$objSysInfo = CreateObject("ADSystemInfo")
? "User name: " + $objSysInfo.UserName

From there you can check for the OU you are searching for.

Top
#195124 - 2009-07-30 09:51 AM Re: Check OU... [Re: Arend_]
vdias Offline
Fresh Scripter

Registered: 2009-07-29
Posts: 8
Loc: Villaverde del Rio, Sevilla, S...
But how do i put that on the kx file?

In my netlogon i point to a .bat that executes wkis32.exe map.kx...

Where do i put that code?

Top
#195126 - 2009-07-30 10:22 AM Re: Check OU... [Re: vdias]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
in the map.kx
Top
#195127 - 2009-07-30 10:25 AM Re: Check OU... [Re: Arend_]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
This is not the fastest way to implement it but it gives you an idea of how it works:
 Code:
Dim $objSysInfo, $arrDN, $strDN
$objSysInfo = CreateObject("ADSystemInfo")
$arrDN = Split($objSysInfo.UserName,",")
For Each $strDN in $arrDN
  If $strDN = "OU=TheNameOfMyOU"
    Use X: \\server\share
  EndIf
Next

Top
#195128 - 2009-07-30 10:43 AM Re: Check OU... [Re: Arend_]
vdias Offline
Fresh Scripter

Registered: 2009-07-29
Posts: 8
Loc: Villaverde del Rio, Sevilla, S...
If InOU(XXXXX)=1
use T: "\\XXXX\XXX"
EndIf

Why something doesn't work too?

Top
#195129 - 2009-07-30 10:52 AM Re: Check OU... [Re: vdias]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
That does not work because there is no build in InOU() function in kixtart. There also is no InOU() UDF posted here.

If you want you can create a UDF or somebody else can but until then you cannot use it like that.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#195130 - 2009-07-30 11:02 AM Re: Check OU... [Re: Mart]
vdias Offline
Fresh Scripter

Registered: 2009-07-29
Posts: 8
Loc: Villaverde del Rio, Sevilla, S...
I found this...

http://www.scriptlogic.com/kixtart/FunctionLibrary_ViewFunction.aspx?ID=InOU

But no idea what to do with it...

Top
#195131 - 2009-07-30 11:08 AM Re: Check OU... [Re: Mart]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Ok, found a InOU() function at scriptlogic.
http://www.scriptlogic.com/kixtart/FunctionLibrary_ViewFunction.aspx?ID=InOU

The example below works but you can only check one OU. If a user is a member of the users OU in the Finance OU and an other user is a member of the Users OU in the Warehouse OU then it will both return 1 (is a member). Maybe it can be altered a bit to support sub OU's but I have time to figure out what to modify right now.

 Code:
Break on

$IsComputer = ""
$OUName = "Users"

$rc = InOU($OUName, $IsComputer)
? $rc
Sleep 5


Function InOU($OUName, Optional $IsComputer)    ; (Standalone version restricted to Windows 2000 and XP systems)
	Dim $OUelement
	    
	If Len($IsComputer) > 0
		$IsComputer = 1
	Else
		$IsComputer = 0
	EndIf
	    
	$InOU = 0
	    
	If Len($_InOUUser) > 0 And Len($_InOUComputer) > 0
		If $IsComputer = 0
			If $_InOUUser = "Initialized but no OU available"
				Return
			EndIf
			For Each $OUelement in Split($_InOUUser, ",")
				If $OUElement = $OUName $InOU = 1 EndIf
			Next
		Else
			If $_InOUComputer = "Initialized but no OU available"
				Return
			EndIf
			For Each $OUelement in Split($_InOUComputer, ",")
				If $OUElement = $OUName $InOU = 1 EndIf
			Next
		EndIf
	Else
		$sysinfo = CreateObject("adsysteminfo")
		If $sysinfo <> 0
			For Each $OUelement in Split($sysinfo.username, ",")
				If Left($OUelement, 3) = "OU="
					$_InOUUser = $_InOUUser + SubStr($OUelement, 4) + ","
					If $IsComputer = 0
						If SubStr($OUelement, 4) = $OUName $InOU = 1 EndIf
					EndIf
				EndIf
			Next
			If Len($_InOUUser) = 0
				$_InOUUser = "Initialized but no OU available"
			EndIf
			            
			For Each $OUelement in Split($sysinfo.computername, ",")
				If Left($OUelement, 3) = "OU="
					$_InOUComputer = $_InOUComputer + "," + SubStr($OUelement, 4)
					If $IsComputer = 1
						If SubStr($OUelement, 4) = $OUName $InOU = 1 EndIf
					EndIf
				EndIf
			Next
			If Len($_InOUComputer) = 0
				$_InOUComputer = "Initialized but no OU available"
			EndIf
		EndIf
	EndIf
	    
EndFunction


Edited by Mart (2009-07-30 11:09 AM)
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#195132 - 2009-07-30 11:10 AM Re: Check OU... [Re: Mart]
vdias Offline
Fresh Scripter

Registered: 2009-07-29
Posts: 8
Loc: Villaverde del Rio, Sevilla, S...

Mart, where do i put all this code? on the kx file?

Top
#195133 - 2009-07-30 11:25 AM Re: Check OU... [Re: vdias]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Like Apronk already said you should put it in map.kx.

The code I posted is not ready finished code for you to use. It is just an example of how to use the InOU() function. You should add the actions to map a drive when the user is a member of the OU.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#195134 - 2009-07-30 11:37 AM Re: Check OU... [Re: Mart]
vdias Offline
Fresh Scripter

Registered: 2009-07-29
Posts: 8
Loc: Villaverde del Rio, Sevilla, S...
something must be wrong...

Copy+paste all code from

Function InOU($OUName, Optional $IsComputer) ; (Standalone version restricted to Windows 2000 and XP systems)

to

Endfunction

and after add...

If InOU ("XXXXXXX")=1
use Q: "\\XXXXX\XXX"
EndIF

and it nothing happens...

Top
#195136 - 2009-07-30 12:29 PM Re: Check OU... [Re: vdias]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
InOU() is posted in the Resources / Kix Function Library on my web site and works fine with all Kix versions. It is a local-only variant for use with login scripts. It checks to see if the local user is a member of a specific OU, and allows partial and exact matches.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#195138 - 2009-07-30 12:54 PM Re: Check OU... [Re: Glenn Barnas]
vdias Offline
Fresh Scripter

Registered: 2009-07-29
Posts: 8
Loc: Villaverde del Rio, Sevilla, S...
Glenn,

Just copy all code to my mapdrive.kx

and after wrote...

If InOU ("XXXXXXX")=1
use Q: "\\XXXXX\XXX"
EndIF

and nothing happens...

Can you send me a example or something...

Top
#195141 - 2009-07-30 02:17 PM Re: Check OU... [Re: vdias]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
My AD structure looks something like this:
 Code:
USA
 - <other divisions>
 - IS
   - 783-Tech Services
   - <other departments>
AUS
 - <other divisions>
 - IS
   - 964-Tech Services
   - <other departments>


So, this simple code:
 Code:
If InOU('AUS')
  'In AUS' ?
Else
  'Not in AUS' ?
EndIF

If InOU('USA')
  ' In USA' ?
Else
  'Not in USA' ?
EndIf


If InOU('783-Tech Services')
  ' In Tech Services' ?
Else
  'Not in Tech Services' ?
EndIf
Function InOU() goes here . . .
can tell me if I'm in Austrailia or the US, and if I'm in the US Tech Services dept. I just tested this code here with the function from my web site.

Get rid of the "=1", since functions that return boolean values won't necessarily return "1", but any non-zero value (often -1).

Note that my InOU function can do partial matches - if you have a "Operations" OU and a "Network Operations" OU, calling InOU('operations') will return true for either. Use the "Strict" option to force an "OU=Operations" match via InOU('operations', 1).

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#195142 - 2009-07-30 02:32 PM Re: Check OU... [Re: Glenn Barnas]
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
VDias -
Take a look at this FAQ How to use UDF's
_________________________
Today is the tomorrow you worried about yesterday.

Top
#195165 - 2009-07-31 08:16 AM Re: Check OU... [Re: Gargoyle]
vdias Offline
Fresh Scripter

Registered: 2009-07-29
Posts: 8
Loc: Villaverde del Rio, Sevilla, S...
Everything working now...

Using Glenn udf (thanks a lot Glenn!) and the following code:

If InOu (XXXXXXXXX)
use Q: "\\XXXX\XXXXX\XXXXX"
use X: "\\XXXX\XXXXX\XXXXX"
Shell "xxxxxxxxxxxxxxxxxxxxx"
EndIf

Thanks a lot to everyone!

Top
Page 1 of 1 1


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

Who's Online
0 registered and 2220 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.082 seconds in which 0.054 seconds were spent on a total of 13 queries. Zlib compression enabled.

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