The Win32 Network Management APIs 44






NetShareSetInfo() Program Example


This function sets the parameters of a shared resource. If 503 is specified for the level parameter, the remote server specified in the shi503_servername member of the SHARE_INFO_503 structure must have been bound to a transport protocol using the NetServerTransportAddEx() function. In the call to NetServerTransportAddEx(), either 2 or 3 must have been specified for the level parameter, and the SVTI2_SCOPED_NAME flag must have been specified in the SERVER_TRANSPORT_INFO_2 structure for the transport protocol. The following code sample demonstrates how to set the comment associated with a shared resource using a call to the NetShareSetInfo() function. To do this, the sample specifies information level 1004 (SHARE_INFO_1004).

Create a new empty Win32 console application project. Give the project name and change the project location is needed.


NetShareSetInfo() Program Example: Creating new C++ Win32 console application project


Then, add the source file and give it a suitable name.


NetShareSetInfo() Program Example: Adding new C++ source file for the C++ source code


Then, add the following source code.


#include <windows.h>

#include <stdio.h>

#include <lm.h>


#pragma comment(lib, "Netapi32.lib")


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


   SHARE_INFO_1004 p;


   DWORD parm_err = 0;




         wprintf(L"Usage: %s server share \"remark\"\n", argv[0]);

         wprintf(L"Example: %s BigdotServer mysharefolder \"This shared folder contains virus!\"\n", argv[0]);




      // Fill in SHARE_INFO_1004 structure member.


      // 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.



              wprintf(L"NetShareSetInfo() is OK!\n");

              wprintf(L"Share remark was set successfully!\n");




              wprintf(L"NetShareSetInfo() failed! Error: %u\tparmerr = %u\n", res, parm_err);



   return 0;



We will set or change the share Comment for the shared folder.


NetShareSetInfo() Program Example: The shared folder comment that will be edited programmatically


Build and run the project. The following screenshot is a sample output.


NetShareSetInfo() Program Example: A sample program output


Verify our previous action.


NetShareSetInfo() Program Example: A shared folder's comment has been changed programmatically





< Win32 Network Management APIs 43 | Win32 Network Management APIs | Win32 Programming | Win32 Network Management APIs 45 >