954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How can we assign or revok permission to users on apllications through C#.NET?

How can we give permissions or revoke permissions on applications(i.e installed softwares) for a user via c#.net.
i have get the all uers list on the computer and also installed programs list but how can i change a user permissions in a way that he may not able to use some specific application like photoshop, corel draw.

Detailed Description of Problem
I have three users 'A' , 'B' and 'C' on my Computer (Standalone) . I want that Only User 'A' can use Photoshop and User 'B' can only use coreldraw. So how we can give permissions to User 'A' and 'B'. I want to do this programmaticaly through C#.NET.

please help me to solve this problem.

Thanks

ashok90
Newbie Poster
1 post since Sep 2009
Reputation Points: 10
Solved Threads: 0
 

Not sure how you would do that by registered application, but here is a good link/example code showing how to add/revoke privileges to particular directory for user. You could change it also to use the File class objects instead of the Directory objects if you desire. I know it's probably not exactly what you are looking for, but maybe a workaround if needed:

Security Access Control

DdoubleD
Posting Shark
996 posts since Jul 2009
Reputation Points: 341
Solved Threads: 233
 

I can suggest to use AOP http://www.postsharp.org it helps very well...

Ramy Mahrous
Postaholic
2,196 posts since Aug 2006
Reputation Points: 480
Solved Threads: 276
 

I found this code, but havn't tried it. It shows how to revoke registry privilege for software application, and I think it might be more of what you are looking for.

public static void RevokeRegKeyRights(RegistryKey regKey,
                                      NTAccount user,
                                      RegistryRights rightsFlags,
                                      InheritanceFlags inherFlags,
                                      PropagationFlags propFlags,
                                      AccessControlType actFlags)
{
    RegistrySecurity regSecurity = regKey.GetAccessControl();

    RegistryAccessRule rule = new RegistryAccessRule(user, rightsFlags, inherFlags,
                                                     propFlags, actFlags);
    regSecurity.RemoveAccessRuleSpecific(rule);

    regKey.SetAccessControl(regSecurity);
}


I believe that if you call the above with the RegistryRights.ExecuteKey option, it should prevent that user from launching the application:

NTAccount user = new NTAccount(@"WRKSTN\ST");

            using (RegistryKey regKey = Registry.LocalMachine.OpenSubKey(
                                    @"SOFTWARE\MyCompany\MyApp"))
            {
                RevokeRegKeyRights(regKey, user, RegistryRights.ExecuteKey,
                               InheritanceFlags.None, PropagationFlags.None,
                               AccessControlType.Allow);
             }
DdoubleD
Posting Shark
996 posts since Jul 2009
Reputation Points: 341
Solved Threads: 233
 

Sorry you need to apply permission on your developed application or another applications
In case of another applications, you may the one who has the administrative permission and when install log on the i.e. 'A' account and right click on the exe and run it as administrator enter your username and password and in installation progress say just for this user. (Just if the application supports that)
You need to disable some user permissions....

Ramy Mahrous
Postaholic
2,196 posts since Aug 2006
Reputation Points: 480
Solved Threads: 276
 

You need to block a pogram execution instead of setting/resetting permission.

__avd
Posting Genius (adatapost)
Moderator
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: