Home All Groups Group Topic Archive Search About

How to Create Share Folder only to one user ?

Author
23 Oct 2006 2:43 AM
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());
            }
        }

Author
24 Oct 2006 2:09 AM
Huffman Hwang
help!

Show quote
"HuffmaN" <huffman.hw***@gmail.com> дÈëÏûÏ¢ÐÂÎÅ:edZ$i0k9GHA.2***@TK2MSFTNGP04.phx.gbl...
> 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());
>            }
>        }
>

AddThis Social Bookmark Button