![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Newbie Rep Power: 3 ![]() | How to programmatically modify the users full control Dear, Forgive me, if I have posted in wrong forum. Please point me to the correct forum for my enquiry below. As we are updating our program and installer to support Vista, we need to programmatically modify the windows folder's Users rights. For example: - We created a folder under "C:\ProgramData\Test\" and store some files which our program need to update when it runs. - Works fine in Administrator mode. - In Standard user mode it does not work as the folder does not have the full rights. If we go to administrator account, select the above folder, right click to select Properties, Security tab, select Users and apply 'Full control' then works fine in standard user. Can we set the Users full controls programmatically? Is there any other approach? Thanks in advance. Regards, MA |
My System Specs![]() |
| | #2 (permalink) |
| Newbie Rep Power: 3 ![]() | Re: How to programmatically modify the users full control Dear, I am trying to give full rights to a folder in Vista so my program can modify the files in the folder in Admin/Standard user mode. The folder I am creating is under "C:\ProgramData" folder. The code below execute without any error but the "Users" account don't get the full rights. Thanks in advance for looking at my post and your expert advice. ============================================================== using System.IO; using System.Security.Principal; using System.Security.AccessControl; static void Main(string[] args) { string folderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Test_folder"); if (!Directory.Exists(folderPath)) Directory.CreateDirectory(folderPath); UpdateAccountRightrs(folderPath); Console.ReadLine(); } /// <summary> /// Iterate each account and update rights /// </summary> /// <param name="folderPath"></param> private static void UpdateAccountRightrs(string folderPath) { Console.WriteLine("-> UpdateAccountRightrs() folderPath: " + folderPath); FileSecurity security = File.GetAccessControl(folderPath); AuthorizationRuleCollection acl = security.GetAccessRules(true, true, typeof(System.Security.Principal.NTAccount)); foreach (FileSystemAccessRule ace in acl) { string accountName = ace.IdentityReference.Value; Console.WriteLine("-> UpdateAccountRightrs() Account: " + accountName); Console.WriteLine("-> UpdateAccountRightrs() Rights: " + ace.FileSystemRights); Console.WriteLine("-> UpdateAccountRightrs() Account: " + accountName); if (ace.FileSystemRights != FileSystemRights.FullControl) ProvideFullRights(folderPath, accountName); } Console.WriteLine("<- UpdateAccountRightrs()"); } /// <summary> /// Provide the full rights to the account /// </summary> /// <param name="filePath"></param> /// <param name="accountName"></param> private static void ProvideFullRights(string folderPath, string accountName) { Console.WriteLine("-> ProvideFullRights() accountName: " + accountName); if ((folderPath.Length == 0) || (accountName.Length == 0)) return; FileSecurity fs = File.GetAccessControl(folderPath); fs.AddAccessRule(new FileSystemAccessRule(accountName, FileSystemRights.FullControl, AccessControlType.Allow)); File.SetAccessControl(folderPath, fs); Console.WriteLine("<- ProvideFullRights()"); } ====================================================== Regards, MA |
My System Specs![]() |
| | #3 (permalink) | ||||||||||||
| Guest | Re: How to programmatically modify the users full control Happs wrote:
Have you tried the Visual Studio group in case someone has already figured this out? You could post the same question again to both groups (thus seeing all answers in both places) or if you post separately you might let the folks in both groups know if you got an answer. I can't help personally but have a feeling that the system is designed to not allow you to do what you wish to do. | ||||||||||||
My System Specs![]() | |||||||||||||
| | #4 (permalink) | ||||||||||||
| Guest | Re: How to programmatically modify the users full control "Happs" <guest@xxxxxx-email.com> wrote in message news:21bc9e7ad0b193382685688b109f45d3@xxxxxx-gateway.com...
You need to set the ACLs during the install. The install needs to run with Administrator privileges. Don't give Users Full Control. Figure out exactly what is needed and give them the needed permissions. At most they need Modify. This is the way secure OS' are supposed to work. Users can change user settings. Administrators can change system settings. http://msdn.microsoft.com/en-ca/wind...a/default.aspx -- Kerry Brown MS-MVP - Windows Desktop Experience: Systems Administration http://www.vistahelp.ca/phpBB2/ | ||||||||||||
My System Specs![]() | |||||||||||||
| | #5 (permalink) | ||||||||||||
| Guest | Re: How to programmatically modify the users full control "Happs" <guest@xxxxxx-email.com> wrote in message news:21bc9e7ad0b193382685688b109f45d3@xxxxxx-gateway.com...
use the ATL security classes as they seem to provide the easiet interface to use for C++ programmers to adjust ACLs. You may wish to take a step back though and examine whether you application truly needs to set ACLs. If the data is user-based rather than program-wide data that should be shared by all users, you will need to rethink your strategy and start storing data in the recommended locations. -Pete | ||||||||||||
My System Specs![]() | |||||||||||||
| | #6 (permalink) |
| Newbie Rep Power: 3 ![]() | Re: How to programmatically modify the users full control Thank you all for your response. Regards, MA |
My System Specs![]() |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| HowTo programmatically define roles and users ... | herbert | .NET General | 1 | 03-25-2008 09:36 PM |
| Full Control to Users programmatically | vovan | Vista account administration | 56 | 05-26-2007 05:46 AM |
| Full Control to Users programmatically | vovan | Vista General | 55 | 05-25-2007 02:54 PM |
| Full Control to Users programmatically | vovan | Vista networking & sharing | 55 | 05-25-2007 02:54 PM |
| is there some location (c.f. [CommonAppData]) where even limited users can modify/write files? | Bob Eaton | Vista file management | 15 | 03-20-2007 03:25 AM |