Adding a remark to the Windows 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: [url=http://www.tenouk.com/clabworksheet/windowspsdk.html]Windows Platform SDK[/url]

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: Adding a remark to the Windows shared folder using C program

To show: Various network management functions - sharing resources

 

// link to the netapi32.lib

// The return value of share functions code can be found in the Windows Network Management Error Codes in MSDN

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

#define _WIN32_WINNT 0x0501

// #define UNICODE - already unicode set by the compiler

 

#include <windows.h>

#include <stdio.h>

#include <lm.h>

 

// accept 3 arguments...

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

{

SHARE_INFO_1004 p;

NET_API_STATUS res;

DWORD parm_err = 0;

 

if(argc < 4)

{

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

printf("Usage: %ls mypersonal testshare \"changing the share remarks\"\n", argv[0]);

}

else

{

// Fill in SHARE_INFO_1004 structure member.

p.shi1004_remark = argv[3];

// Call the NetShareSetInfo function, specifying information level 1004.

res = NetShareSetInfo(argv[1], argv[2], 1004, (LPBYTE)&p, &parm_err);

 

// Display the result of the call.

if(res == 0)

printf("Remark for the %ls share successfully set.\n", argv[2]);

else

printf("Cannot set the \"remark\", error: %u parmerr = %u\n", res, parm_err);

}

return 0;

}

 

Output example:

(This program run at the command prompt)

 

F:\vc2005project\cplus\debug>cplus

Usage: cplus <server_name> <share_name> <share "remark">

Usage: cplus mypersonal testshare "changing the share remarks"

F:\vc2005project\cplus\debug>cplus mypersonal testshare "A new share remarks"

Remark for the testshare share successfully set.

F:\vc2005project\cplus\debug>

 

 

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