Share a Folder by Programmation

  • Thread starter Thread starter Guest
  • Start date Start date
Franky said:
How to Share a Folder by Programmation?

One posibility to do this is through the System.Management classes and WMI.
Here's a sample:
....
using (ManagementClass o = new ManagementClass("\\\\.\\root\\cimv2",
"Win32_Share", null))
{
string wmiMethod = "create";
ManagementBaseObject inputArgs = o.GetMethodParameters(wmiMethod);
inputArgs["Name"] = "yourShareName";
inputArgs["Path"] = "c:\\yourFolderPath";
inputArgs["Description"] = "some description";
inputArgs["Type"] = 0; // Disk share
ManagementBaseObject outParams = o.InvokeMethod(wmiMethod, inputArgs,
null);
uint ret = (uint)(outParams.Properties["ReturnValue"].Value);
if(ret != 0)
Console.WriteLine("Failed {0}", ret);
}


Willy.
 
Back
Top