Archives For VB.NET – Windows API

Useful Windows APIs that I have used in VB.NET

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…

There is no .NET method for creating a network drive yet (as of .NET 4.0) so here is how you can do it using good old Windows APIs 🙂 As well as the API definitions, I’ve included a managed method that wraps up the functionality of the API so that it is easier to use from .NET code.

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…

Here is an example of how you can use the NetShareAdd Windows API to share an existing folder either on your local machine or on a remote machine. Unfortunately there is currently no managed .NET method to do this so Windows API or WMI are the only ways you can do this… and I don’t like WMI for several reasons so I chose the API route.

Continue Reading…

Ever wanted to identify the Process that started another process (for example you might want to find out which process launched your application) ? Well I’ve finally got some code working that gets the ID of the process that created the process you specify.

Continue Reading…

I recently had a need in one of my programs to loop through all network drives on a computer and get the drive letter and the UNC path that the network drive mapped to. I thought this would be easy with the System.IO.DriveInfo.GetDrives method but unfortunately it was not as the DriveInfo class offers no way to retrieve the UNC path that the network drive maps to. After a bit of research I could find no better way than using a Windows API (I’m not a fan of WMI!). Here is some example VB.NET code that I have written that will do this:

Continue Reading…

Here’s some code I wrote recently that uses the GetProfileType Windows API to determine what type of profile the currently logged on user is using.

Continue Reading…

The example code below will detect when a USB drive is connected and will then look for a file named test.txt in the USB drive.

Continue Reading…