Are you running this on a 64-bit operating system by any chance?
PS I have found a bug in it that I need to fix, so if you can hang on until tonight when I can fix this and re-upload it that would be good![]()
Are you running this on a 64-bit operating system by any chance?
PS I have found a bug in it that I need to fix, so if you can hang on until tonight when I can fix this and re-upload it that would be good![]()
Last edited by chris128; Oct 20th, 2009 at 03:54 AM.
My free .NET Windows API library (Version 2.2 Released 12/06/2011)
Blog: cjwdev.wordpress.com
Web: www.cjwdev.co.uk
Yes!![]()
Well then you need to change your project properties to compile to x86 rather than x64 or AnyCPU. By default when you create a new project on a 64 bit OS it will make the project a 64 bit project (well it will set it to AnyCPU but on a 64bit OS that means 64 bit) and 64 bit programs cannot work with 32 bit programs directly. My control is a 32 bit program so that is why you are getting that error.
To get around this you can make your project 32 bit (aka x86) by going into Project Properties (double click where it says My Project) and then the Compile tab on the left, then click the Advanced Compile Options button and then change the box that says AnyCPU so that it says x86. Click Save and then try and add the control again
PS look at the note I added in to my previous post as well.
My free .NET Windows API library (Version 2.2 Released 12/06/2011)
Blog: cjwdev.wordpress.com
Web: www.cjwdev.co.uk
Thanks chris128 - I have got the control working. Very nice!
Look forward to using your updated version later.
Last edited by thrillseeker; Oct 20th, 2009 at 05:10 AM.
Good stuffLet me know if you have any problems or find any bugs.
Also, when I upload the new version I will provide instructions for how to make it show the correct images for each object (basically just involves assigning an ImageList to the treeview just like you would with any other treeview but giving the images for users, computers, OUs etc a specific name)
My free .NET Windows API library (Version 2.2 Released 12/06/2011)
Blog: cjwdev.wordpress.com
Web: www.cjwdev.co.uk
OK the new version is now uploaded - See the original post in this thread for the download and updated information on the control.
Here is a break down of all of the methods, properties and events:
Methods
Fills the treeview with objects from the active directory path passed in. This method does not block the calling thread (so it will not freeze your program while it runs) and by default it is 'recursive' - which means it will load every object it can find into the tree straight away rather than just loading one level and then loading the child objects when you expand a node. This behaviour can be changed by setting the LoadOnDemand property to True.vb Code:
LoadDirectoryObjectsAsync("LDAP://DC=mydomain, DC=local")
Requests that the tree stops loading objects - note that although this method will return immediately, the loading will not stop instantly. It will only cancel once the current object (including any child objects) has finished being loaded. You can test the LoadCancelled property to check to see if the control is in the "cancel pending" state and there is also a property that is passed in to the LoadCompleted event that indicates whether or not the load completed due to being cancelled.vb Code:
CancelLoad()
Properties
If set to True then any groups that are shown in the tree will be expandable - expanding them will show their members but note that groups nested within groups will not be expandable.vb Code:
ExpandGroups
If set to True, child objects of a specific node will only be loaded when that node is expanded. This will be a synchronous operation, so it will block the UI thread while it completes. If you are on the same local network as the domain controller that is providing the responses to the AD queries then this freeze will barely even be noticeable. If you change this property after already loading (or partially loading) the tree then you should call LoadObjectsAsync again.vb Code:
LoadOnDemand
The username to use when connecting to Active Directoryvb Code:
AuthUsername
The password to use when connecting to Active Directoryvb Code:
AuthPassword
You can test this Boolean property to see if the control is currently loading objects in the background due to a call to LoadObjectsAsyncvb Code:
LoadInProgress
Indicates whether or not the current load has been requested to stop. Will be reset to False once the load has completed or has been cancelled successfully.vb Code:
LoadCancelled
Events
Raised when the control has either finished loading objects or when it has been cancelled. This event may not be raised if an exception is thrown during the load (need to work on the error handling for future versions). You can test the 'e.LoadCancelled' property that is passed in to this event to see if the event was raised due to the load being cancelled. If the LoadOnDemand property has been set then this event will be raised each time child objects have finished being loaded (so every time the user expands a node)vb Code:
LoadCompleted
Raised just before the control starts to load a new object from Active Directory. You can check the 'e.CurrentObjectPath' property passed to this event to see the LDAP path for the object that is about to be loaded. Intended to be used as some kind of progress report to show that something is happening.vb Code:
LoadingObjectChanged
EDIT: See this post for properties and events new for version 1.5 : http://www.vbforums.com/showpost.php...3&postcount=67
Thats all for now - If anyone has any problems or comments then please post them![]()
Last edited by chris128; Apr 24th, 2010 at 12:38 PM.
My free .NET Windows API library (Version 2.2 Released 12/06/2011)
Blog: cjwdev.wordpress.com
Web: www.cjwdev.co.uk
hi chris, thanks for answering my question....
I'll try your new version as soon as I get back home.
For now I would like to ask a small request... is it possible for you to add a filter on your ADTreeview... for example I want to display only the Users or only the OU on my domain. thanks...
Ah yes that is a good idea, as I'm guessing most of the time that people would use something like this it is for the user to select a specific type of object. I will add that for the next version.
In the mean time, with the current control, you would have to just check the ADObjectType property of the selected node to make sure it is the correct type for what you want them to select
My free .NET Windows API library (Version 2.2 Released 12/06/2011)
Blog: cjwdev.wordpress.com
Web: www.cjwdev.co.uk
great!!! Thanks![]()
Hi Chris
How do I associate ContextMenuStrip on your ADTreeView? I have 3 different ContextMenuStrip and I want to display different CMS whenever I click a node. For example If I right click a User Node then I'm going to display the CMS for User Object and if I right click the group node then I'm going to display the CMS for Group Object same goes for OU Object. Appreciate any help, thanks!
Hi Chris,
Any update on this? Thanks![]()
I havent had chance to do any more work on the control to add a filtering option yet, and as for the context menu I think you would have to just handle the NodeMouseClick event and then check to see if it is the right mouse button that has been pressed, then check the ADObjectType property of the node that was clicked and show the relevant context menu based on that.
My free .NET Windows API library (Version 2.2 Released 12/06/2011)
Blog: cjwdev.wordpress.com
Web: www.cjwdev.co.uk
hi,
nice tool - i have a problem with the performance of it.
we have about 10000 users and groups. it takes about 2min for complete loading. i dont need the users, groups.... the only thing i need OU's.
do you have time for the filter option?
thanks
As I explained in post #46 (http://www.vbforums.com/showpost.php...7&postcount=46 ), there is a property you can set that stops it from loading the entire AD structure straight away. The property is named LoadOnDemand, so just set that to True and then each OU/container will only be loaded when someone actually tries to expand it. That should save your users from having to wait for more than a couple of secondsLet me know how it goes.
Oh and yeah I will get the filter thing done soon!![]()
My free .NET Windows API library (Version 2.2 Released 12/06/2011)
Blog: cjwdev.wordpress.com
Web: www.cjwdev.co.uk
great!!! thx!!!! works perfect!
thanks chris!
Already found - I have to wait for filter..
--
Hi
Is there possible to hide some type of AD entries eg computers? Or only to show OU-s and Users.
Last edited by Raivo.Metsvaht; Nov 23rd, 2009 at 11:17 AM.
I'll try and put aside some time over the next couple of days to get a filter property working and get some better error handling in there. Will update this thread when complete!
My free .NET Windows API library (Version 2.2 Released 12/06/2011)
Blog: cjwdev.wordpress.com
Web: www.cjwdev.co.uk
Hi
Is there possibility programmatically select a node of ADTreeview? Actually I need to select first node (domain) after loading AD.
Raivo
You would do that in the exact same way that you would do it in a normal treeview control
My free .NET Windows API library (Version 2.2 Released 12/06/2011)
Blog: cjwdev.wordpress.com
Web: www.cjwdev.co.uk
This is the question – how to do that?
Chris, it is against forum rules to attach binary files or archives containing binary files. You need to remove that attachment and attach the project it was built from.
2007-2013
Why is my data not saved to my database? | Communicating between multiple forms | MSDN Data Walkthroughs
MSDN "How Do I?" Videos: VB | C#
VBForums Database Development FAQ
My CodeBank Submissions: VB | C#
My Blog: Using Parameters in ADO.NET | Keyboard Events | Assemblies & Namespaces
Oh sorry, I thought it was just EXE's not DLLs as well. I'll remove it and upload the solution file later today.
My free .NET Windows API library (Version 2.2 Released 12/06/2011)
Blog: cjwdev.wordpress.com
Web: www.cjwdev.co.uk
Hi chris123, I have been using your ADtreeView and just want to say its made my life allot easier so thanks very much. Looking forward to the filter update as mentioned in previous posts.
Thanks for the positive feedbackI'll try and spend some more time on this soon and get the filter option sorted.
And sorry I forgot to remove the DLL file and upload the project file JMC, I'll do it tonight!
My free .NET Windows API library (Version 2.2 Released 12/06/2011)
Blog: cjwdev.wordpress.com
Web: www.cjwdev.co.uk
By the way, do you know of any way to catch errors. In my project I require the user to type a domain name in, the project then converts the domain name to a usable LDAP format and calls the "LoadDirectoryObjectsAsync" method. This is fine unless the user types in the wrong domain name, the project returns a "DirectoryServicesCOMException" and closes. I have tried placing the method inside a try method and using a catch as exeption to try and grab hold of the error but it does not work. Any ideas?
Yeah the Try/Catch probably doesnt work because the control uses a background thread to actually do the AD searching so the exception is not actually raised from the method that you are calling. In the next version I will make it catch all errors in the internal code and either make it just raise an event and pass the exception information to that event, or make it return exception information in the LoadCompleted event.
As a workaround for now, you could try just using the Application.UnhandledException event and checking the type of exception thrown
My free .NET Windows API library (Version 2.2 Released 12/06/2011)
Blog: cjwdev.wordpress.com
Web: www.cjwdev.co.uk
New version (1-5) uploaded to original post in this thread. Here's the new stuff:
Property - ShowContainersAndOUsOnly
Set this to true before calling the LoadDirectoryObjectsAsync method and the treeview will only show the containers and OUs (and the top level domain) rather than showing users and groups etc
Property - LdapPrefix
This string will be added to any LDAP queries that are done from the control internally as a result of LoadDirectoryObjectsAsync being called - it will be added after the LDAP:// but before the rest of the LDAP path, so you can use it to specify a server for all of the LDAP queries to go to (very handy if like me you want to use this from a machine that is not joined to the domain you are loading). This prefix is not applied to the path that you specify initially when calling LoadDirectoryObjectsAsync though, but because you can specify that yourself you can just add the prefix in yourself.
Overloaded version of LoadDirectoryObjectsAsync
There is now a parameterless version of LoadDirectoryObjectsAsync which will attempt to bind to the root of the domain your computer is joined to, rather than you having to supply a specific LDAP path for the tree to start at.
Event - ExceptionThrown
Raised when an exception is thrown in the background thread that loads the AD objects, so now you can handle this to see why the tree view is not loading. The original exception is passed in along with a string containing any relevant additional information.
My free .NET Windows API library (Version 2.2 Released 12/06/2011)
Blog: cjwdev.wordpress.com
Web: www.cjwdev.co.uk
Righto, so I've a form with your control on it. I use the LoadDirectoryObjectsAsync method and......it does nothing. Nothing added to Treeview, no errors. Just...nothing.
Any idea what I might have not done?
Last edited by Ginolard; May 25th, 2010 at 04:34 AM.
ManagePC - the all-in-one PC management and inventory tool
lol was the first post too long to read :P There was a link in it that points you to this post for the description of all the methods and events etc:
http://www.vbforums.com/showpost.php...7&postcount=46
and this one shows the new methods/events in the updated version:
http://www.vbforums.com/showpost.php...3&postcount=67
The first method mentioned in that first link (LoadDirectoryObjectsAsync) is the one that actually loads the tree view, so that accepts a an argument that is the LDAP path you want to loadAlso, in the new version you can just not pass in any arguments and it will bind to the root of the domain.
My free .NET Windows API library (Version 2.2 Released 12/06/2011)
Blog: cjwdev.wordpress.com
Web: www.cjwdev.co.uk
Ah, you obviously replied to my pre-edit post
I've found that method now but nothing happens. This is what I have and the treeview remains steadfastly empty.
Code:Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.AdTreeView1.ExpandGroups = True Me.AdTreeView1.LoadDirectoryObjectsAsync("<My_LDAP_PATH"> End Sub
ManagePC - the all-in-one PC management and inventory tool
It might just be that it is taking a while to loop through all of the objects in AD - remember the method is Asynchronous so it works in the background. If you want to see which objects it is currently loading (to verify that it is actually doing something) then handle the LoadingObjectChanged event and use the e.CurrentObjectPath property that is passed in to that event. You can also handle the ExceptionThrown event to see if an error is occurring in the background thread that is stopping the treeview from loading the AD structure.
If you dont want the treeview to load the entire AD structure in one go, which can take a little while, then set the LoadOnDemand property to true before calling LoadDirectoryObjectsAsync.
My free .NET Windows API library (Version 2.2 Released 12/06/2011)
Blog: cjwdev.wordpress.com
Web: www.cjwdev.co.uk
Ah that was it. Was just taking a long time. Funnily enough, I built a Treeview for my app (see my sig) that does EXACTLY the same thing!
I didn't bother making it a separate control though. Now I can't decide whether to stick with my code or use your control![]()
ManagePC - the all-in-one PC management and inventory tool
ah cool, I might download your app and take a look
EDIT: Hmm when I run your application if I put my IP address in then the program freezes for quite a while (might be worth using a background thread so it doesnt do this) and then it comes up with the following error:
EDIT EDIT: Also - in the software tab it shows the Office 2007 SP2 about 7 times, shows 4 items that just have a weird symbol as the name, shows the MS Help Viewer twice, shows that I have both IE 7 and IE 8 installed (which is not possible), and a few other glitches. You might want to try using my class for enumerating software here: http://www.vbforums.com/showthread.php?t=598355 (it works on remote machines as well)System.Reflection.TargetInvocationException: An exception occurred during the operation, making the result invalid --> System.Management.ManagementException: Not Found![]()
Last edited by chris128; May 25th, 2010 at 05:36 AM.
My free .NET Windows API library (Version 2.2 Released 12/06/2011)
Blog: cjwdev.wordpress.com
Web: www.cjwdev.co.uk
It's a bit more limited as it doesn't show users (as that's not within the scope of my application).
ManagePC - the all-in-one PC management and inventory tool
Well the only issue with your treeview is that it doesnt display a + symbol next to any of the folders, but I dont know if you are too bothered about thatSee my previous post as well as I've edited some bugs in your app into there.
EDIT: Another issue with your app, some of the environmental variables are listed several times (TEMP and TMP in particular)
Also, the Mapped Drives section on the Summary tab only detects drives that have been mapped with the "reconnect at logon" box ticked, it does not detect drives mapped via logon script or group policy. If you want to get all mapped drives, just loop through the IO.DriveInfo.GetDrives collection and check the DriveType property of each one to see if it is a network drive - then to get the UNC path that the drive is mapped to, you can use this Windows API that I posted on my blog a while ago: http://cjwdev.wordpress.com/2009/12/...network-drive/
Last edited by chris128; May 25th, 2010 at 05:56 AM.
My free .NET Windows API library (Version 2.2 Released 12/06/2011)
Blog: cjwdev.wordpress.com
Web: www.cjwdev.co.uk
Thanks for the comments. I'll look into the GetDrives method. As for the environment variables, I know about that one. It's because it lists all the environment variables for all users.
Edit: The GetDrives method doesn't seem to support execution against remote machines. Now that I think about it, I remember trying it way back when. I've never found a fully reliable method for enumerating all network drives on remote machines.
Also, my Treeview does show + symbol next to the folders but only after they've been enumerated.
Last edited by Ginolard; May 25th, 2010 at 06:55 AM.
ManagePC - the all-in-one PC management and inventory tool
Wow, I love how this work, but I have one issue with it. I am using 2010 express and compiling in 2.0. I am not able to use the control with 2.0. If I change it to 4.0, I can use the control and it works. Am I missing something?
My free .NET Windows API library (Version 2.2 Released 12/06/2011)
Blog: cjwdev.wordpress.com
Web: www.cjwdev.co.uk
I think I found the issue. 2010 Express will force you to convert your old project when you first load it. Once that's done you can go back and change the framework from 4.0 to 2.0 and it will convert it back to the 2.0 framework. It looks like something goes wrong with that conversion back to 2.0. It's still trying to reference some 4.0 stuff. I used another computer that had 2005 express on it to compile the dll. I then imported it with my 2010 project and it works!
I am having an issue with it hanging when I click on the "groups" in my domain. We have a few hundred, but it should not take that long. I have another OU that contains about 1300 more OU's and it loads in just a few seconds. Any ideas?
Thanks! Chad
Ah yeah I have seen that problem actually with 2010 not working very well when you change the target framework. It does my head in because on my work PC for some reason when I have any project target 3.5 or 2.0 it goes slow as hell so I just make them target 4.0 and it runs fine, but then when I want to work on the project at home I change it back to targeting 3.5 and it almost always screws something up
As for the groups - have you got it set so that it displays members of the groups? I think the property is called ExpandGroupMembers or something like that. If so then do you mean when you try to expand a group or do you just mean when you click on a group to select it?
My free .NET Windows API library (Version 2.2 Released 12/06/2011)
Blog: cjwdev.wordpress.com
Web: www.cjwdev.co.uk