Sharing windows folder

A

Anand G

All,

How do I share Windows folder programatically? Which namespace/class to look
for?

Thanks in advance for your help.

regards,
Anand
 
W

Willy Denoyette [MVP]

| All,
|
| How do I share Windows folder programatically? Which namespace/class to
look
| for?
|
| Thanks in advance for your help.
|
| regards,
| Anand
|
|

System.Management and the WMI class Win32_Share.

Following is a sample, that exports c:\\temp as Testshare...



public enum SharedDevice{
Disk = 0,
PrintQueue = 1,
Device = 2,
IPC = 3
}


....
using (ManagementClass o = new ManagementClass("root\\cimv2",
"Win32_Share", null))
{
ManagementBaseObject inputArgs = o.GetMethodParameters("Create");
inputArgs["Name"] = "Testshare";
inputArgs["Path"] = "c:\\temp";
inputArgs["Description"] = "This is public test share";
inputArgs["Type"] = SharedDevice.Disk;
ManagementBaseObject outParams = o.InvokeMethod("Create", inputArgs,
null);
uint ret = (uint)(outParams.Properties["ReturnValue"].Value);
if(ret != 0)
// handle failure....
}
}

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

Top