Removing a shared folder


Compiler: Visual C++ Express Edition 2005

Compiled on Platform: Windows Xp Pro SP2

Target platform: none, just for learning and fun

Header file: Standard and Windows

Additional library: Windows Platform SDK

Additional project setting: Set project to be compiled as C

Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C Code (/TC)

Other info: non-CLR or unmanaged. Need to add netapi32.lib (netapi32.dll) to the project. Click the Project menu->Select the your_project_name Properties... sub menu->Expand the Configuration Properties folder on the left pane->Expand the Linker subfolder->Select the Input subfolder->Select the Additional Dependencies field on the right pane->Click the ... at the end of the field->Type in 'netapi32.lib' in the empty pane->Click the OK button->Click the OK button second time to close the project Properties dialog.

To do: Removing the Windows shared folder using C program

To show: More on the various network management C functions - sharing the Windows resources



// Add the netapi32.lib...

// Network Management Error Codes, Platform SDK: Network Management

// For Win Xp Pro, adjust accordingly for other Windows version

#define _WIN32_WINNT 0x0501


// #define UNICODE - already compiled as unicode set by compiler


#include <windows.h>

#include <stdio.h>

#include <lm.h>


int wmain(int argc, TCHAR *argv[ ])




if(argc != 3)


printf("Usage: %ls <server_name> <share_name>\n", argv[0]);

printf("Example: %ls mypersonal testshare\n", argv[0]);




// Call the NetShareDel() function to delete the share.

res = NetShareDel(argv[1], argv[2], 0);


// Display the result of the call.

if(res == 0)

printf("%ls share successfully removed.\n", argv[2]);


printf("Something wrong, error: %u\n", res);


return 0;



Output example:

(This program run at the command prompt)



Usage: cplus <server_name> <share_name>

Example: cplus mypersonal testshare


F:\vc2005project\cplus\debug>cplus mypersonal

Usage: cplus <server_name> <share_name>

Example: cplus mypersonal testshare


F:\vc2005project\cplus\debug>cplus mypersonal testshare

testshare share successfully removed.





Verify that the share has been removed through the Windows explorer.



C and C++ Programming Resources | C & C++ Code Example Index