Archives For vb.net

I’m often asked if I can include attributes from a user’s Terminal Services Profile tab in their AD properties in AD Info and AD Tidy, but for whatever reason MS decided to store these attributes in a very strange format so it is not easy. I’ve finally spent some time on it and got something working now and thought I would share my results (and frustration) with the rest of the community in case it helps anyone else out.

Continue Reading…

Just a quick example of how you can use the System.DirectoryServices.DirectorySearcher class to find deleted objects (that have not yet reached the tombstone time limit) in your Active Directory domain.

Continue Reading…

Well getting the power scheme APIs working on Windows 7 and Vista is taking a little longer than expected so I thought I would bring this new version out without the power related methods so that people can use the other new methods sooner rather than later. Download link for new version is at the end of this post, but I encourage you to read the full post to see what has changed in this version.

Continue Reading…

Here is a little VB.NET function I’ve written that will provide you with the names of all of the domain controllers in your Active Directory domain – note that you need to add a reference to System.DirectoryServices first.

Continue Reading…

This is the first official release of my .NET Windows API pack – a class library that is intended to make it easier to work with several native Windows APIs from managed .NET code. There are over 50 Windows APIs defined in this library and roughly 30 managed methods that use these APIs to provide functionality that is not available in the .NET Framework today. Many more will be included in the next version but hopefully this first version will still be useful to a lot of people.

Continue Reading…

I have nearly finished the first release of my Windows API pack, which is a class library (DLL) that makes using certain Windows APIs from .NET code easier and simpler. You just add a reference to this class library and then you can call managed .NET methods from the library rather than having to figure out how to use the Windows APIs yourself. So far I have got just over 25 managed methods in this library, which makes use of roughly 45 Windows APIs. You can see a list of my managed methods and a description for each one below:

Continue Reading…

I’ll start off by saying that there is not much use for this because ordinarily you would use the .NET Framework’s built in Process class, but there are some rare scenarios where that is not possible so hopefully this will help some of you in that situation out. Basically this is a small  vb.net app that demonstrates how to redirect the input and output of a console application that you have launched via the CreateProcess API (or CreateProcessAsUser etc).

Continue Reading…

I wrote this code primarily to be able to get the windows services running in each svchost.exe process, however it can be used against any process to see which services (if any) are running within it. It makes use of the EnumServicesStatusEx, OpenSCManager, and CloseServiceHandle Windows APIs. If you are not a developer and just want to see which services are in an svchost.exe process, see this post

Continue Reading…

I’ve been working on this for a few days and have finally got it doing what it is supposed to do, so thought I would post it here in case it helps someone else out. Basically this VB.NET code will get the command line for an external process, even if your application did not start that process (which is the limitation you have if you try using Process.StartInfo). This gets the full command line that was used to start the process so it includes the path to the executable and any command line arguments / parameters specified.

Continue Reading…

I recently needed to get the command line arguments that an external process was started with (one that was not started by my application, svchost.exe to be specific) and found that the only way I could get this information was with Windows APIs. The API in question just returned pointers that references locations in the memory of the external process (which meant I could not use the .NET Marshal methods as they would treat the pointers as references to my own process’s memory – thanks to wj32 for helping me understand that) so I had to use the Windows API ReadProcessMemory. I will be posting my full example of how to get the command line parameters for an external process soon but for now I thought I would just post this .NET class I wrote that makes reading process memory a bit easier as it does all of the API work for you.

Continue Reading…

Well I’ve just spent ages trying to figure out how to get the window icon (the icon displayed in the title bar at the far left) for an external program window from a VB.NET  app – tried using GetClassInfo, GetClassInfoEx, GetClassLong, GetWindowLong and a few other APIs… only to find that you can simply use SendMessage to send the WM_GETICON message and it returns a handle to the icon – and this works perfectly *for most windows* (I’ll explain in a moment). So for anyone else wanting to do the same thing in the future, here’s a basic vb.net example of how to get the window icon from a window.

Continue Reading…

Here’s yet another .NET wrapper/helper that I’ve written for some Windows API functionality. This time my code makes use of about 6 different Windows APIs to provide you with a method that will return a list of all windows that are currently open on the computer along with their handle, title bar text, class name and the process that owns the window.

Also might be worth mentioning: I’m going to be releasing a class library soon full of lots of these “.NET friendly” methods that I’ve written to make calling specific Windows APIs simpler and easier. So you can just add a reference to the class library DLL and then you can avoid having to use the APIs directly as you can just use my nice simple .NET methods, with no need to marshal anything across to unmanaged code. Check back on this blog soon if that sounds like something you would be interested in.

Continue Reading…

As I demonstrated how to map a network drive in my last post, it seems like it might be a good idea to explain how to delete an existing mapped drive as well. Again we have to rely on Windows APIs to do this… but its a pretty simple one this time (for once).

Continue Reading…

Perhaps this is common knowledge for a lot of people but even though I have been working with Windows APIs from VB.NET quite a lot recently, I did not know about this little ‘trick’ until today.

Continue Reading…

As mentioned in my previous post I have been working on figuring out how to set share permissions (not NTFS permissions) from a VB.NET app for the last couple of days… and I have finally got it working. This code makes use of the NetShareAdd Windows API along with several others to create the share and the ACL to go with it that specifies the permissions. Note that this can also be run against remote computers to create shares on them as well.

Continue Reading…