0

C# を使用してフォルダーを作成し、ネットワーク上で共有しています。

if (!System.IO.Directory.Exists(FolderPath))
{
      System.IO.Directory.CreateDirectory(FolderPath);
      // Calling Win32_Share class to create a shared folder
      ManagementClass managementClass = new ManagementClass("Win32_Share");
      // Get the parameter for the Create Method for the folder
      ManagementBaseObject inParams = managementClass.GetMethodParameters("Create");
      ManagementBaseObject outParams;
      // Assigning the values to the parameters
      inParams["Description"] = Description;
      inParams["Name"] = ShareName;
      inParams["Path"] = FolderPath;
      inParams["Type"] = 0x0;
      // Finally Invoke the Create Method to do the process
      outParams = managementClass.InvokeMethod("Create", inParams, null);
      // Validation done here to check sharing is done or not
      if ((uint)(outParams.Properties["ReturnValue"].Value) != 0)
      {
           //MessageBox.Show("Folder might be already in share or unable to share the directory");
      }
}

XP では動作しますが、Windows 7 ではこのコードからフォルダーを共有できません。

C# を使用して Windows 7 でフォルダーを共有する方法を誰か教えてもらえますか?

4

2 に答える 2

0

フォルダーを共有するには、アプリケーションを管理者アクセスで実行する必要があります。

次のリンクを見ると、あなたが扱っているのと同じ状況のように見えることが書かれています。半分ほど下に、Windows 7 マシンで動作するために必要な追加のアクションを説明する受け​​入れられた回答があります。

リンク: http://social.msdn.microsoft.com/Forums/en-US/windowssdk/thread/de213b61-dc7e-4f33-acdb-893aa96837fa

お役に立てれば

于 2013-04-15T11:17:39.687 に答える
0

を交換してください

\ 

あなたの道で

/
于 2018-09-25T17:41:12.820 に答える