Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Problem getting shared folder that created by code using Win32_LogicalShareSecuritySetting [modified]

Problem getting shared folder that created by code using Win32_LogicalShareSecuritySetting [modified]

Scheduled Pinned Locked Moved C#
databasesecurityhelptutorialquestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cyn8
    wrote on last edited by
    #1

    Hi, How to get a list of all the shared folder and get the share permission for each one? I tried to use ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_LogicalShareSecuritySetting"); But the line of code above does not return shared folder created by code. If i manually create the folder and set it as Shared folder through windows, the shared folder can be obtain from Win32_LogicalShareSecuritySetting. Just for information, the share and security setting for both folder created through code and manually created is the same. But if the shared folder created using code, it fails to return using Win32_LogicalShareSecuritySetting. If i use Win32_Share, i'm able to get all the share folders but the problem is i cannot use the method ("GetSecurityDescriptor") below to obtain the AccessMask or the share permission information. It will throw exception because GetSecurityDescriptor is not a method under Win32_Share: ManagementBaseObject outParamsMthd = m.InvokeMethod("GetSecurityDescriptor", null, options); Below is the code snippet to obtain shared folder permission information for user name "Everyone"

    ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_LogicalShareSecuritySetting");
    ManagementObjectSearcher searcher = new
    ManagementObjectSearcher(scope, query);

                    ManagementObjectCollection queryCollection = searcher.Get();
                    foreach (ManagementObject m in queryCollection)
                    {
                        string shareName = m\["Name"\].ToString();
                        string shareLocalPath = ShareManager.GetShareLocalPath(shareName);
                        Console.WriteLine(shareLocalPath);
                        if (folderPath == shareLocalPath)
                        {
                            InvokeMethodOptions options = new InvokeMethodOptions();
    
                            ManagementBaseObject outParamsMthd =
                            m.InvokeMethod("GetSecurityDescriptor", null, options);//GetSecurityDescriptor
                            ManagementBaseObject descriptor =
                            outParamsMthd\["Descriptor"\] as ManagementBaseObject;
    
                            ManagementBaseObject\[\] dacl = descriptor\["DACL"\] as
                            ManagementBaseObject\[\];
    
                            foreach (ManagementBaseObject ace in dacl)
                            {
                                Manag
    
    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups