The best and easiest method to do Windows Administrative tasks from code is through WMI. Almost anything can be done on a Windows machine, local or remote, through WMI.
In order to administer a Windows shared folder you will need to interact with the Win32_Share
WMI class.
Sample on how to use WMI to create a shared folder:
ManagementPath path = new ManagementPath("Win32_Share");
path.Server = "."; // Change this to your server
object[] parameters = new object[] {
"C:\\TestShare", // Path to shared folder
"Test Share", // Share name
0x0, // Share type (disk drive)
5, // Maximum amount of concurrent users
null, // Password (optional)
null // Security level (optional)
};
ManagementClass share = new ManagementClass(path);
object result = share.InvokeMethod("Create", parameters);
You will need to add a reference to the System.Management
assembly in order to access the WMI classes. You'll also need access to the remote machine of course.
Check out the WMI Reference for more details. Specifically check out the Win32_Share Class reference on what all the parameters and return codes mean.