Create a folder share?

  • Thread starter Thread starter pnp
  • Start date Start date
P

pnp

Hi all,
How can I make a folder shared from a pc through C# code?
Thanks in advance,
Peter
 
Easy, Using System.Management classes....


using System.Management;
....

using (ManagementClass o = new ManagementClass("\\\\.\\root\\cimv2",
"Win32_Share", null))
{
string method = "create";
ManagementBaseObject inputArgs = o.GetMethodParameters(method);
inputArgs["Name"] = "SharedTemp"; // share as
inputArgs["Path"] = "c:\\temp"; // directory to share
inputArgs["Description"] = "this is public share";
inputArgs["Type"] = 0; // 0 = Disk share type
ManagementBaseObject outParams = o.InvokeMethod(method, inputArgs, null);
uint ret = (uint)(outParams.Properties["ReturnValue"].Value);
if(ret != 0)
Console.WriteLine("Failed {0}", ret);
}

Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top