How to create share only to one user ?

H

HuffmaN

My code goes here following, but it can't work, why ? Bytheway,if only one
user should be permitted to accesss it,how can i do ? thx!

static void Main(string[] args)
{
try
{
ManagementObject v_theTrusteeObject = new
ManagementClass("Win32_Trustee").CreateInstance();
Object[] v_theSID = {1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0};
v_theTrusteeObject["Domain"] = null;
v_theTrusteeObject["Name"] = "Everyone";
v_theTrusteeObject["SID"] = v_theSID;

ManagementObject v_theAceObject = new
ManagementClass("Win32_Ace").CreateInstance();
v_theAceObject["AccessMask"] = 2032127;
v_theAceObject["AceFlags"] = 3;
v_theAceObject["AceType"] = 0;
v_theAceObject["Trustee"] = v_theTrusteeObject;

ManagementObject v_theSecDescObject = new
ManagementClass("Win32_SecurityDescriptor").CreateInstance();
Object[] v_theAceArray = { v_theAceObject };
v_theSecDescObject["DACL"] = v_theAceArray;

ManagementClass v_theShareClass = new
ManagementClass("Win32_Share");
ManagementBaseObject v_theShareArguments =
v_theShareClass.GetMethodParameters("Create");
v_theShareArguments["Path"] = @"D:\Media";
v_theShareArguments["Name"] = "Media";
v_theShareArguments["Type"] = 0;
v_theShareArguments["Access"] = v_theSecDescObject;

ManagementBaseObject v_theCreateResult =
v_theShareClass.InvokeMethod("Create", v_theShareArguments, null);
Console.WriteLine(v_theCreateResult.GetText(TextFormat.Mof));

foreach (ManagementObject v_aShareObject in
(new ManagementObjectSearcher("select * from
Win32_Share")).Get())
{
Console.WriteLine(v_aShareObject["Name"]);
}
}
catch(Exception v_theConnectionException)
{
Console.WriteLine(v_theConnectionException.ToString());
}
}
 

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