PC SOFT
ONLINE REPOSITORY
FOR WINDEVWEBDEV AND WINDEV MOBILE

Home |  | Sign in | English US
WD Active Directory DotNet
Published by Boller
in the category Tools
New features



Description
WD Active Directory DotNet .net

PROCEDURE REFProperties()

sNode is string // TreeView node in the main window
sTempString is string // String that contains the identifier of each TreeView leaf (and therefore the value of the property)
sDomain is string // Name of the parent domain
i is int = 1 // Counter
sDescription is string // Description of the group
sNodeGroup is string // Node of the treeview of groups
nHundredthsNanosecond is 8-byte int // Number of hundredths of nanosecond passed between 01/01/1601 at noon and the time of the last connection

// Retrieve the selected node
sNode = TreeSelect(WIN_Main.TREE_Item)

// Concatene the node found with the name of the user
sNode += TAB + WIN_Main.TABLE_ITEM.COL_Value[gnLine]


// Retrieve the common name
sTempString = TreeIdentifier(WIN_Main.TREE_Hidden, sNode +TAB+ "cn")
STC_CN = ExtractString(sTempString, 2, TAB)

MyWindow..Title = StringBuild(MyWindow..Title,ExtractString(sTempString, 2, TAB))


// Retrieve the display name
sTempString = TreeIdentifier(WIN_Main.TREE_Hidden, sNode +TAB+ "Displayname")
STC_DISPLAYNAME = ExtractString(sTempString, 2, TAB)

// Retrieve the login
sTempString = TreeIdentifier(WIN_Main.TREE_Hidden, sNode +TAB+ "samaccountname")
IF sTempString = "" THEN
STC_INITIALS = "The property does not exist"
ELSE
STC_INITIALS = ExtractString(sTempString, 2, TAB)
END

// Retrieve the groups to which this user belongs
sTempString = TreeIdentifier(WIN_Main.TREE_Hidden, sNode +TAB+ "memberOf")
sTempString = ExtractString(sTempString, 2, TAB)

// Extract the domain name (starts from the end)
sDomain = ExtractString(sTempString, 1, ",", FromEnd)

WHILE sDomain <> "" AND sDomain <> EOT

// Refresh the node where the group must be added
sNodeGroup += sDomain[[ 4 TO]]

// Retrieve the description of the relevant group
sDescription = ExtractString(TreeIdentifier(WIN_Main.TREE_Hidden, sNodeGroup + TAB + "description"), 2)

// Adds the group into the treeview
TreeAdd(TREE_GROUP, sNodeGroup, tvDefault, tvDefault, sDescription)

// Adds TAB at the end of the node
sNodeGroup += TAB

// Goes to next one
i++
sDomain = ExtractString(sTempString, i, ",", FromEnd)

END

// Expands the TreeView
TreeExpandAll(TREE_GROUP)
TreeSelectPlus(TREE_GROUP, TREE_GROUP[1])
ExecuteProcess(TREE_GROUP, trtSelection)

// Retrieve the date of the last connection
sTempString = TreeIdentifier(WIN_Main.TREE_Hidden, sNode +TAB+ "Lastlogon")


// Retrieve the number of hundredths of nanosecond passed since 1st January 1601 at noon
nHundredthsNanosecond = Val(ExtractString(sTempString, 2))
IF nHundredthsNanosecond > 0 THEN
STC_LASTCONNECTION = TransformDate(nHundredthsNanosecond)
ELSE
STC_LASTCONNECTION = "Unknown"
END



// Retrieve the Admin property
sTempString = TreeIdentifier(WIN_Main.TREE_Hidden, sNode +TAB+ "AdminCount")
CBOX_ADMIN = Val(ExtractString(sTempString, 2))



//------------------------------------------------

// Syntax:
//[ <Result> = ] TransformDate (<nHundredthNanoSeconds> is int)
//
// Parameters:
// nHundredthNanoSeconds (integer): Number of nanoseconds
// Return value:
// variant: Formatted date

PROCEDURE TransformDate(LOCAL nHundredthsNanosecond is int)

nSeconds is 8-byte int
nNbDays is int
dtDateTime is DateTime

// Transform the number of hundredths of nanosecond into seconds
nSeconds = nHundredthsNanosecond / Power(10,7)

// Retrieve the number of years since 1601
dtDateTime..Year = IntegerPart(nSeconds / (60*60*24*365.25))

// Subtract the number of years (changed into seconds) from the total number of seconds and calculate the number of days
nSeconds -= dtDateTime..Year * 60*60*24*365.25
nNbDays = nSeconds /(60*60*24)

// Subtract the number of seconds from the days and calculate the number of hours
nSeconds -= nNbDays * (60*60*24)
dtDateTime..Hour = nSeconds / 3600

// Subtract the number of seconds from the hours and calculate the number of minutes
nSeconds -= dtDateTime..Hour * 3600
dtDateTime..Minute = nSeconds / 60

// Refresh the date in datetime format
dtDateTime..Month = 1
dtDateTime..Year += 1601
dtDateTime..Day = 1
dtDateTime..Day += nNbDays



RESULT StringBuild("The %1 at %2 ",DateToString(dtDateTime..Date,"MM/DD/YYYY"),TimeToString(dtDateTime..Time,"HH:MM"))

//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

PROCEDURE CheckFramework()

// Tries to read the setup location of the .NET framework
IF RegistryQueryValue("HKEY_LOCAL_MACHINE\SOFTWARE\MICROSOFT\.NETFramework\","InstallRoot") = "" THEN
RESULT False
ELSE
RESULT True
END

//-----------------------------------------------------------------------------------


PROCEDURE DoubleClick()


nRow is int

// Retrieve the selected row
nRow = TABLE_ITEM

// Check the validity of the row
IF nRow =-1 THEN
RETURN
END

IF TABLE_ITEM.COL_Type[nRow] = "Enter" THEN
TreeSelectPlus(TREE_Item,TreeSelect(TREE_Item) + TAB + TABLE_ITEM.COL_Value[nRow])
ExecuteProcess(TREE_Item,trtSelection)
END

//----------------------------------------------------------------------------------------------------------------------------------


PROCEDURE FillItemList(LOCAL sTVName is string <useful>, LOCAL sNode is string, LOCAL sElement is string, LOCAL nLevel is int)


sIdentifier is string

IF nLevel <> 1 THEN
RESULT True
END

sIdentifier = TreeIdentifier(TREE_Hidden, sNode + sElement)


IF sIdentifier = "" THEN
// It's a node
// Add to the list
TableAddLine(TABLE_ITEM, IMG_Directory, "CN", sElement, "Enter")

ELSE
// Add into the table
TableAddLine(TABLE_ITEM, IMG_Prop, sElement, ExtractString(sIdentifier, 2), ExtractString(sIdentifier, 3))
END

RESULT True

//------------------------------------------------------------------------------------------------------------------

// Syntax:
//GetProperties (<pclResult>, <sNode> is string)
//
// Parameters:
// pclResult: Initialized SearchResult .NET object corresponding to an item of the active directory
// sNode (ANSI string): Node of the item whose properties are requested
// Return value:
// None

PROCEDURE GetProperties(LOCAL pclResult, LOCAL sNode is string)

pclPropertyDirectory is ResultPropertyCollection dynamic // .NET object (PropertyCollection) that will contain the collection of all the properties for an entry
pclPropertyTab is IEnumerable dynamic // .NET object (IEnumerable) that will contain the names of the properties
pclTabValues is IEnumerable dynamic // NET object (IEnumerable) that will contain the values of the properties
pclPropEnumerator is IEnumerator dynamic // NET object (IEnumerator) that will enumerate the properties
pclValEnumerator is IEnumerator dynamic // NET object (IEnumerator) that will enumerate the properties
bPropRes,bValRes are booleans // Booleans used to find out whether the move to the next one in the enumerator was successful
sPropertyName is string // Name of the property
pclEnumValue is IEnumerator dynamic // NET object (IEnumerator) that will enumerate the values of the properties
parrValue is array dynamic // An Array type may be returned when retrieving the values, this variable is used to host the value
sValue is string // Value of the property


// Retrieve the collection of properties
pclPropertyDirectory = pclResult:Properties


// Retrieve the collection of property names
pclPropertyTab = pclPropertyDirectory:PropertyNames

// Retrieve the collection of property values
pclTabValues = pclPropertyDirectory:Values

// Retrieve an enumerator on both sets
// These enumerators allow you to browse the properties and their values
pclPropEnumerator = pclPropertyTab:GetEnumerator()
pclValEnumerator = pclTabValues:GetEnumerator()

// Position on the first element
// Because a .NET enumerator points to nothing by default
bPropRes = pclPropEnumerator:MoveNext()
bValRes = pclValEnumerator:MoveNext()

// As long as the positioning to the next one is OK
WHILE bPropRes = True AND bValRes = True

// Retrieve the current object (the name of the property)
sPropertyName = pclPropEnumerator:Current

// Retrieve an enumeration on the value of sPropertyName
pclEnumValue = pclPropertyDirectory:get_Item(sPropertyName):GetEnumerator()

// Point to the start of the enumeration
pclEnumValue:MoveNext()


// This part is found in WHEN EXCEPTION IN
// because the concatenation of "P" + TAB + EnumValue:Current + TAB + "Text Attribute"
// can disable an exception when the value of the property is an array
WHEN EXCEPTION IN


// Tests the property in order not to display the path of this entry
IF sPropertyName <> "adspath" THEN // If the property is named adspath, don't display it because it is the access path to this 'directory'
sValue = pclEnumValue:Current
// Add the entry to the cache TreeView
TreeAdd(TREE_Hidden, sNode +TAB+ sPropertyName, tvDefault, tvDefault, "P" +TAB+ sValue +TAB+ "Text Attribute")
END

DO

// An exception was triggered,
// it's an array, retrieve the array
IF ExceptionInfo(errCode)<> 1036 THEN
parrValue = pclEnumValue:Current

nBound is int = Dimension(parrValue)
// Browse the array and add the value to the string
FOR i = 1 TO nBound
// Increment the result string
sValue += Upper(NumToString(parrValue[i], "02X")) + " "
END
// Adds the entry to the cache TreeView
TreeAdd(TREE_Hidden, sNode +TAB+ sPropertyName, tvDefault, tvDefault, "P" +TAB+ sValue +TAB+ "Binary Attribute")
END

END

// Moves to the next property and to the next value
bPropRes = pclPropEnumerator:MoveNext()
bValRes = pclValEnumerator:MoveNext()
END


//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

// Syntax:
//[ <Result> = ] bCheckLogin (<sServerAddress> is string, <sNameUserToConnect> is string, <sPassword> is string)
//
// Parameters:
// sServerAddress (ANSI string): Name or IP address of the server
// sNameUserToConnect (ANSI string): Name of the user who must be connected
// sPassword (ANSI string): Password of the user
// Return value:
// boolean: True if the connection was successful
// False otherwise

PROCEDURE bCheckLogin(LOCAL sServerAddress is string, LOCAL sNameUserToConnect is string, LOCAL sPassword is string)

// Create the .NET object (DirectoryEntry) used to connect to the active directory
MyUser is DirectoryEntry ("LDAP://" + sServerAddress, sNameUserToConnect, sPassword)

// Name of the user (property of directory entry)
sUserName is string

// To check whether a password is valid, try to connect to the active directory
// and get the exceptions disabled by the framework,
// If a member can be accessed without disabling an exception, the password is valid
// otherwise the password is invalid

WHEN EXCEPTION IN
// attempt to access the Name property of DirectoryEntry object
sUserName = MyUser:Name
DO
// Wrong password
// return False
RESULT False
END

// At this point, no exception was disabled
RESULT True


//-----------------------------------------------------------------------------------------------------------------------------------------

// Syntax:
//FillUserList ()
//
// Parameters:
// None
// Return value:
// None

PROCEDURE FillUserList()

// Local variables
clFindDirectory is DirectorySearcher(gclObjDirEnt) // NET object (DirectorySearcher) used to perform searches in the Active Directory
pclResultList is SearchResultCollection dynamic // .NET object (SearchResultCollection) used to retrieve all the search results
pclResult is SearchResult dynamic // NET SearchResult object containing ONE search result
sUserName is string

//Search is a dynamic DirectorySearcher
clFindDirectory:Filter = "(objectClass=user)"


WHEN EXCEPTION IN
// Retrieve the information
pclResultList = clFindDirectory:FindAll()
DO
// Error message
Error("Unable to connect to the Active Directory of " + gsDomain,"You have no sufficient rights to list the users")
// Closes the window
Close()
END
// If no result
IF pclResultList:count = 0 THEN
// Error message
Error("No user found in the Active Directory","Check you rights, you may not have sufficient rights to list the users")
// Closes the window
Close()
END

// Upper Bound
nBound is int = pclResultList:Count - 1
// Browse the results
FOR i = 0 TO nBound

// Retrieves the .NET object (SearchResult)
pclResult = pclResultList:get_item(i)
// Extract the name
sUserName = ExtractString(pclResult:path, 1, ",")
// Defines the path
sUserName = Replace(sUserName, "LDAP://" + gsDomain + "/CN=", "")
// Search with this path
clSearch is DirectoryEntry (pclResult:path)
// Adds the name to the list
ListAdd(COMBO_USER, gLink(pclResult:path) + sUserName)

END

// Sorts the list by ascending order of user name
ListSort(COMBO_USER, True)
Illustrations, screen shots
none
none
User reviews
(To evaluate this resource, click 'Write a review')
No review or comment? Be the first one!