0

I'm doing a Deployment Project in VS2008, and at the end of the installation flow I need to create a shared folder with Full Control permissions to Everyone on the local machine accessible from a company domain. I succeeded to create the shared folder, but Everyone has read access. Any help on how to do this would be appreciated.

Thank you, Valeriu

Valeriu
  • 69
  • 1
  • 6

1 Answers1

0

I assume you're using the ManagementClass to create a shared folder.

Setting the Access field of your ManagementBaseObject should give full control to everyone:

ManagementClass mc = new ManagementClass("win32_share");
ManagementBaseObject inParams = mc.GetMethodParameters("Create");
inParams["Description"] = "Shared Folder";
// ... whathever ...
inParams["Access"] = null; // <-- should give full control access to everyone

If the above doesn't work you might wanna try explicitly setting the security level with smt like the following:

    public static void AddDirectorySecurity(string FileName, string Account, FileSystemRights Rights, AccessControlType ControlType)
    {
        DirectoryInfo dInfo = new DirectoryInfo(FileName);

        DirectorySecurity dSecurity = dInfo.GetAccessControl();

        // Add the FileSystemAccessRule to the security settings.  
        dSecurity.AddAccessRule(new FileSystemAccessRule(Account,
                                                         Rights,
                                                         ControlType));
        // Set the new access settings. 
        dInfo.SetAccessControl(dSecurity);
    } 

If none of the above helps, then I'd suggest you post your code.

JohnIdol
  • 48,899
  • 61
  • 158
  • 242
  • The code is nothing special. The installer just creates a directory on the local machine and tries to share it. I tried your code also, but still doesn't work. The ManagementClass mc = new ManagementClass("win32_share"); code, indeed, shares the directory over the domain, but only with Read access to Everyone. The AddDirectorySecurity method does nothing. – Valeriu Nov 24 '09 at 07:52
  • Would this be because the Installer is running with the System user and that doesn't have enough permissions? – Valeriu Nov 24 '09 at 07:53
  • 1
    I also think that inParams["Access"] = null; gives access to Everyone, but read-only – Valeriu Nov 24 '09 at 08:05