Determining if a folder is shared in .NET

后端 未结 4 915
情书的邮戳
情书的邮戳 2020-11-30 12:42

Is there a way through the .net framework to determine if a folder is shared or not?

Neither Diretory, DirectoryInfo or FileAttributes seem to have any corresponding

4条回答
  •  -上瘾入骨i
    2020-11-30 13:08

    One more way to skin this cat is to use powershell (if you have it installed) to invoke the wmi call, include a reference to System.Management.Automation, it will most likley be in \program files\reference assemblies\microsoft\windowspowershell

    private void button1_Click(object sender, EventArgs e)
    {
      Runspace rs = RunspaceFactory.CreateRunspace();
      rs.Open();
      Pipeline pl = rs.CreatePipeline();
      pl.Commands.AddScript("get-wmiobject win32_share");
    
      StringBuilder sb = new StringBuilder();
      Collection list = pl.Invoke();
      rs.Close();
      foreach (PSObject obj in list)
      {
        string name = obj.Properties["Name"].Value as string;
        string path = obj.Properties["Path"].Value as string;
        string desc = obj.Properties["Description"].Value as string;
    
        sb.AppendLine(string.Format("{0}{1}{2}",name, path, desc));
      }
      // do something with the results...
    }
    

提交回复
热议问题