A
ad
Dear Sir,
I want to make a folder shared with adsi with C#.
Are there any example about it?
I want to make a folder shared with adsi with C#.
Are there any example about it?
Willy Denoyette said:You need to add a reference to the activeds.tlb
(%windir%\system32\activeds.tlb), and include a using directive to import
this activeds namespace.
using System;
using System.DirectoryServices;
using ....
using(DirectoryEntry lanmanserver = new
DirectoryEntry("WinNT://yourmachinename/Lanmanserver"))
{
IADsContainer fserv = lanmanserver.NativeObject as IADsContainer;
IADsFileShare sharenew = fserv.Create("fileshare", "NewShare") as
IADsFileShare;
sharenew.Path="C:\\";
sharenew.SetInfo();
}
Another way to achieve the same is by using System.Management classes,
here's a sample:
using System.Management;
...
using (ManagementClass o = new ManagementClass("\\\\.\\root\\cimv2",
"Win32_Share", null))
{
string method = "create";
ManagementBaseObject inputArgs = o.GetMethodParameters(method);
inputArgs["Name"] = "ImASharedfolder";
inputArgs["Path"] = "c:\\temp";
inputArgs["Description"] = "this is temp shared";
inputArgs["Type"] = 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.
ad said:I have find a VB version at
http://support.microsoft.com/kb/169398/en-us?ln=en-us&sd=gn&fr=0
How can I rewrite it in C#