change directory access control for common application data folder failed.
-
Here is my code, and i tried same code for file access control, it works well. but doesn't work for common application data on Vista.
private static void GrantEveryoneFullControlRight(string directory) { try { if (!Directory.Exists(directory)) Directory.CreateDirectory(directory); DirectoryInfo dirInfo = new DirectoryInfo(directory); DirectorySecurity ds = dirInfo.GetAccessControl(AccessControlSections.Access); FileSystemAccessRule rule = new FileSystemAccessRule( "Users", FileSystemRights.FullControl, AccessControlType.Allow); ds.AddAccessRule(rule); dirInfo.SetAccessControl(ds); } catch (Exception ex) { // Logger.WriteLog(LogType.Error, ex.ToString()); Console.WriteLine(ex.ToString()); } }
Glad to discuss with you and best wishes.
-
Here is my code, and i tried same code for file access control, it works well. but doesn't work for common application data on Vista.
private static void GrantEveryoneFullControlRight(string directory) { try { if (!Directory.Exists(directory)) Directory.CreateDirectory(directory); DirectoryInfo dirInfo = new DirectoryInfo(directory); DirectorySecurity ds = dirInfo.GetAccessControl(AccessControlSections.Access); FileSystemAccessRule rule = new FileSystemAccessRule( "Users", FileSystemRights.FullControl, AccessControlType.Allow); ds.AddAccessRule(rule); dirInfo.SetAccessControl(ds); } catch (Exception ex) { // Logger.WriteLog(LogType.Error, ex.ToString()); Console.WriteLine(ex.ToString()); } }
Glad to discuss with you and best wishes.
-
nobody know how to solve this? :sigh: :sigh: :(( :((
Glad to discuss with you and best wishes.
I do something very similar except use "Everyone" in the access rule:
string appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData); string _localUserDataPath = Path.Combine(appDataPath,"My Company\\MyApp\\"); if (!Directory.Exists(_localUserDataPath)) { DirectorySecurity ds = new DirectorySecurity(); ds.AddAccessRule(new FileSystemAccessRule("Everyone", FileSystemRights.FullControl, AccessControlType.Allow)); Directory.CreateDirectory(_localUserDataPath, ds); } else { // the directory exists - lets change security on it DirectoryInfo di = new DirectoryInfo(_localUserDataPath); DirectorySecurity ds = new System.Security.AccessControl.DirectorySecurity(); ds.AddAccessRule(new FileSystemAccessRule("Everyone", FileSystemRights.FullControl, AccessControlType.Allow)); di.SetAccessControl(ds); }
-
I do something very similar except use "Everyone" in the access rule:
string appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData); string _localUserDataPath = Path.Combine(appDataPath,"My Company\\MyApp\\"); if (!Directory.Exists(_localUserDataPath)) { DirectorySecurity ds = new DirectorySecurity(); ds.AddAccessRule(new FileSystemAccessRule("Everyone", FileSystemRights.FullControl, AccessControlType.Allow)); Directory.CreateDirectory(_localUserDataPath, ds); } else { // the directory exists - lets change security on it DirectoryInfo di = new DirectoryInfo(_localUserDataPath); DirectorySecurity ds = new System.Security.AccessControl.DirectorySecurity(); ds.AddAccessRule(new FileSystemAccessRule("Everyone", FileSystemRights.FullControl, AccessControlType.Allow)); di.SetAccessControl(ds); }
-
Well, I thought it was working on Vista but I must have been running my client in admin mode because I can't get it to work again. What does work is creating an installer package for my windows service that creates the directory in ProgramData. Using vs.net 2008 I added a custom folder called Common Application Data Folder (any name will work). I set the DefaultLocation property to [CommonAppDataFolder] and the Property property to COMMONAPPDATAFOLDER. Then I added my own folders to this folder (Company\commondir). When the install is run it creates the folders and adds "Users" to the security properties for those folders. This seems to give "Users" enough permission to read/execute and write files to that location. My non-admin windows client can read/ write and execute from the folder and my windows service can as well.
-
Well, I thought it was working on Vista but I must have been running my client in admin mode because I can't get it to work again. What does work is creating an installer package for my windows service that creates the directory in ProgramData. Using vs.net 2008 I added a custom folder called Common Application Data Folder (any name will work). I set the DefaultLocation property to [CommonAppDataFolder] and the Property property to COMMONAPPDATAFOLDER. Then I added my own folders to this folder (Company\commondir). When the install is run it creates the folders and adds "Users" to the security properties for those folders. This seems to give "Users" enough permission to read/execute and write files to that location. My non-admin windows client can read/ write and execute from the folder and my windows service can as well.