注:他の人物と似ているタイトルに基づいて無視しないでください。フォルダのネットワーク共有に「Everyone」特権を追加する
私はWindows 7マシン上でフォルダを共有しようとしています。そして、私はC#を介して全員に完全な権限を与えたいと思います。
ここでは、これを含む他のページでいくつかの記事を見てきました。しかし、他のいくつかのように、それは私のために動作しません。以下はSOから抜粋したスニペットです。
DirectorySecurity sec = Directory.GetAccessControl(path);
// Using this instead of the "Everyone" string means we work on non-English systems.
SecurityIdentifier everyone = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
sec.AddAccessRule(new FileSystemAccessRule(everyone, FileSystemRights.FullControl | FileSystemRights.Synchronize, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow));
Directory.SetAccessControl(path, sec);
上記のコードを呼び出す前に、フォルダを共有しています。以下の画像は、私が何を得るの結果である:
これまでのところ、とても良いです。しかし、次の画像では残りの2つのチェックボックスがまだチェックされていないことがわかります。
私は何をしてください不足しているのですか?
ありがとうございます!
編集:以下は実際の共有を行うためのコードです。共有およびその下のフォルダに
private static void QshareFolder(string FolderPath, string ShareName, string Description)
{
try
{
ManagementClass managementClass = new ManagementClass("Win32_Share");
ManagementBaseObject inParams = managementClass.GetMethodParameters("Create");
ManagementBaseObject outParams;
inParams["Description"] = Description;
inParams["Name"] = ShareName;
inParams["Path"] = FolderPath;
inParams["MaximumAllowed"] = null;
inParams["Password"] = null;
inParams["Access"] = null;
inParams["Type"] = 0x0; // Disk Drive
// Invoke the method on the ManagementClass object
outParams = managementClass.InvokeMethod("Create", inParams, null);
// Check to see if the method invocation was successful
if ((uint) (outParams.Properties["ReturnValue"].Value) != 0)
{
throw new Exception("Unable to share directory.");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "error!");
}
}
上記の共有に使用されたコードを追加しました。それが私が修正する必要があるのでしょうか? – JimDel
はい。注:両方の部分が必要です。つまり、ACLはすでにフォルダにあり、ACLは共有にあります。 –
リンクをありがとうが、C++の情報は私にはあまり役に立たなかった。 – JimDel