Windows Vista Forums
Vista Forums Home Join Vista Forums Webcasts Windows 7 Forum Vista Tutorials Tags

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.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Vista Newsgroups > Vista security

How to programmatically modify the users full control

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 07-04-2008   #1 (permalink)
Newbie


Join Date: Jul 2008
32
 
Rep Power: 3
Happs is on a distinguished road
  Happs is offline

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 SpecsSystem Spec
Old 07-05-2008   #2 (permalink)
Newbie


Join Date: Jul 2008
32
 
Rep Power: 3
Happs is on a distinguished road
  Happs is offline

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 SpecsSystem Spec
Old 07-05-2008   #3 (permalink)
Charlie Tame
Guest


 

Re: How to programmatically modify the users full control

Happs wrote:
Quote:

> 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
>
>

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 SpecsSystem Spec
Old 07-05-2008   #4 (permalink)
Kerry Brown
Guest


 

Re: How to programmatically modify the users full control

"Happs" <guest@xxxxxx-email.com> wrote in message
news:21bc9e7ad0b193382685688b109f45d3@xxxxxx-gateway.com...
Quote:

>
> 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?
>

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 SpecsSystem Spec
Old 07-10-2008   #5 (permalink)
Pete Delgado
Guest


 

Re: How to programmatically modify the users full control


"Happs" <guest@xxxxxx-email.com> wrote in message
news:21bc9e7ad0b193382685688b109f45d3@xxxxxx-gateway.com...
Quote:

>
> 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.
There are a variety of ways to accomplish what you want to do. I prefer to
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 SpecsSystem Spec
Old 07-10-2008   #6 (permalink)
Newbie


Join Date: Jul 2008
32
 
Rep Power: 3
Happs is on a distinguished road
  Happs is offline

Re: How to programmatically modify the users full control

Thank you all for your response.

Regards,
MA
My System SpecsSystem Spec
Closed Thread

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


Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51