Cjwdev.WindowsAPI API Pack Released

July 4, 2010 — 21 Comments

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.

See this previous post for details of what is included in this library, but note that there have been some slight changes – the main change is that the RenewIPAddress and ReleaseIPAddress methods have not been included. They will be in the next version but I didn’t want to include them as they were not working 100% correctly and didn’t want to delay this first release just for the sake of those 2 methods.

I have included the XML file that provides intellisense descriptions for each of the methods and parameters so you should be able to understand how to use each of the methods just from that but I will be adding some proper documentation here shortly.

All you need to do to use this library is download the ZIP file from the download link below and extract both the DLL and XML files to the same folder, then add a reference from your project to the DLL file (go to the Project menu in Visual Studio and then select Add Reference). Now you can access the various classes and methods in my library by using the Cjwdev.WindowsAPI namespace. For example, to get a list of all visible program windows that are open on the computer you could use: Cjwdev.WindowsAPI.NativeWindow.GetTopLevelWindows or if you wanted to extract all icons from a DLL/ICO file you could use: Cjwdev.WindowsAPI.NativeIcon.GetAllIcons or to remove a windows service: Cjwdev.WindowsAPI.NativeService.DeleteService

Here is the download link:

EDIT: See this post for info and download link for new version.

Please let me know if you have any suggestions for APIs that you would like to see managed version of included in the next version or if you have any feedback on the current version. Either leave a comment here or send me an email at cwright@cjwdev.co.uk


21 responses to Cjwdev.WindowsAPI API Pack Released

    cjconstantine July 11, 2010 at 12:37


    I just added your Cjwdev.WindowsApi pack to my project because I’m interested in using it to replace sc.exe for service creation/removal. But Cjwdev.WindowsApi.NativeService only gives me four options:


    Both the .dll and the .xml files have been unzipped into the same folder. Any ideas?


      Hey, I’m a bit puzzled by that… it only seems to be showing you the Enums. I just tested on my PC to double check I hadn’t made some daft mistake in the DLL but all I had to do was add a reference to the DLL and that was it, I could then access all of the shared methods such as InstallService etc. Here’s a screenshot: http://i135.photobucket.com/albums/q160/chriswright128/CjwdevApi.jpg

      Can you post a screenshot of (or maybe just explain) how/where in your code you are using it?


        cjconstantine July 11, 2010 at 13:30

        Ah! Thank you. I was trying to assign NativeService.InstallService to a variable, like this:

        Dim _service As Cjwdev.WindowsApi.NativeService

        instead of just using it (sorry, still a n00b).


    Thanks for your helpful code samples for sharing a folder — the EXPLICIT_ACCESS and SECURITY_DESCRIPTOR definitions are especially useful and saved me a bunch of time.

    In case it helps, I’ve found that the explicit access permission value for Change Access to a share is decimal 1245631 (Hex 001301BF).


      Glad it was useful 🙂 and thanks for that definition of the Change permission, I spent ages trying to find that or work out what it was and eventually gave up. I’ll be sure to add that to the next version, cheers.


    tnx man.. very helpful..


    Your API is very useful and thanks for sharing it. I have one requirement to get the previous window name (which have focus before). For example, before activating my Window C# Form, I have control on Notepad. Now when I click on Window Form button, I want to display Notepad name i.e. it was previous activated (had focus) before Window form got focus.

    Any idea, how can achieve this. Thanks in advance.


    wow, Chris thanks so much! Such a bonus. I did have one problem that I thought you might know the answer to. I was testing your posted code

    Dim PermissionsList As New List(Of SharePermissionEntry)

    ‘Create a new permission entry for the Everyone group and specify that we want to allow them Read access
    Dim PermEveryone As New SharePermissionEntry(String.Empty, “Everyone”, SharedFolder.SharePermissions.Read, True)
    ‘Create a new permission entry for the currently logged on user and specify that we want to allow them Full Control
    Dim PermUser As New SharePermissionEntry(Environment.UserDomainName, Environment.UserName, SharedFolder.SharePermissions.FullControl, True)

    ‘Add the two entries declared above to our list

    ‘Share the folder as “Test Share” and pass in the desired permissions list
    Dim Result As SharedFolder.NET_API_STATUS = _
    SharedFolder.ShareExistingFolder(“Test Share”, “This is a test share”, “C:\SomeFolder”, PermissionsList)

    ‘Show the result
    If Result = SharedFolder.NET_API_STATUS.NERR_Success Then
    MessageBox.Show(“Share created successfully!”)
    MessageBox.Show(“Share was not created as the following error was returned: ” & Result.ToString)
    End If

    I referenced the cjwdev dll, in my project but the IDE says the SharedFolder class is not declared and may be inaccessable due to it’s protection level. Though it knew SharePermissionEntry but not SharedFolder? any ideas..? Thanks again so much for your work!


      Hi Ned,

      I think you are using the code from my vbforums.com post which had a SharedFolder class attached to it but that is not the exact same code that is in my API library – in the API library everything is split up into different classes that are held in the Cjwdev.WindowsApi namespace and the class that contains the ShareExistingFolder method is called NativeFileSystem, not SharedFolder like it is in the vbforums example. So if you wanted to call the ShareExistingFolder method you would actually need to do this:


      though obviously you can use an Imports statement at the top of your code to import the Cjwdev.WindowsApi namespace so that you don’t have to type that bit each time you use a class/method from my DLL.

      Hope that helps



    ok that’s good I’ll test it out some more soon and let you know. than ks much.


    Hi Chris,

    How’s it going? ok so I retested with the new info you gave me and here is the test code I used

    Imports Cjwdev.WindowsApi.NativeFileSystem

    Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim PermissionsList As New List(Of SharePermissionEntry)

    Dim PermEveryone As New SharePermissionEntry(String.Empty, “Everyone”, SharePermission.FullControl, True)


    ShareExistingFolder(“C:\Testing”, “TestingShare”, ” “, PermissionsList)

    End Sub

    End Class

    This shared the folder, but instead of the everyone group being added it added Users(‘MachineName’).

    I tried this on vista ultimate, 7, and server 2003 R2. Vista and 7 are not part of a domain, just desktops. Am I coding wrong? Thanks so much for your help!!


      OK and what happens when you use that code? Is it still saying ShareExistingFolder is not recognised?
      EDIT: Sorry I obviously didn’t read your post correctly and missed the bit where you said it added the Users group instead of the Everyone group. I can’t explain that… using the exact same code as you it shared the folder and assigned the Everyone group for me. What CPU architecture is your app set to compile for (e.g x86, x64 or AnyCPU) ?


    I’m out of the office now but I’ll check that tomorrow. I bet it was set to AnyCPU but I’ll check it.


    Hi Chris,

    My mistake, the code did work and it was targeted to x86. When I go to the folder properties, and the sharing tab then the permissions button, everyone is in that section. However when I go to the security tab there is not an everyone group there. I need to add the everyone group there in order to have access to the files within the folder. Is this possible with your API? or am I missing something?

    Thanks again I can’t say it enough you have already saved me tons of time.


    All I can say is thatnks again! I have been developing in .Net for a few years now and there is so much diversity. You saved me a ridiculous amount of time here thanks.


    Hi chris you wouldn’t happen to have a cjwdev.windowsapi.dll with a strong name would you?


    All of a sudden VS2010 is giving me an error,
    Unable to emit assembly: Referenced assembly cjwdev.windowsapi does not have a strong name. I tried removing and readding it. also tried tlbimp but that fails too. Searched for solutions but none of them were able to solve the problem. I thought I might have to register the dll before using tlbimp but it failed to register with there may be a corrupt version in memory.. and suggested pview but that didn’t work either lol… I don’t want to bug you with this stuff it’s not your problem Chris, it’s mine lol. I may have to write the windows api code myself? Thought you might have one compiled with a strong name.


    source code available too?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s