2012-04-12 30 views
2

注:他の人物と似ているタイトルに基づいて無視しないでください。フォルダのネットワーク共有に「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); 

上記のコードを呼び出す前に、フォルダを共有しています。以下の画像は、私が何を得るの結果である:

enter image description here

これまでのところ、とても良いです。しかし、次の画像では残りの2つのチェックボックスがまだチェックされていないことがわかります。

enter image description here

私は何をしてください不足しているのですか?

ありがとうございます!

編集:以下は実際の共有を行うためのコードです。共有およびその下のフォルダに

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!"); 
     } 
    } 

答えて

3

アクセス許可が分離されている - あなたのコードは、ファイル/フォルダのACLを設定し...だから、ネットワーク共有自体にACLを設定する部分が欠けています。

最終的に共有経由でファイルにアクセスするときに、ファイルと共有のアクセス許可の最小値を取得します。

共有にACLを設定する方法はわかりませんが、ここでは共有に関するアクセス許可を設定する方法の良い始点かもしれない関連するC++の質問があります:How to create read-only network share programmatically?

+0

上記の共有に使用されたコードを追加しました。それが私が修正する必要があるのでしょうか? – JimDel

+0

はい。注:両方の部分が必要です。つまり、ACLはすでにフォルダにあり、ACLは共有にあります。 –

+0

リンクをありがとうが、C++の情報は私にはあまり役に立たなかった。 – JimDel

関連する問題