Can you gain administrator permission in .NET program?
-
I have noticed that why anti virus, and other programs can gain administrator access when the app started when computer starts? And why not .net created application? If I set to request administrator level in exe manifest, it will prompt user for permission, and it is very annoying since this application is automatically started at computer startup. How do I gain administrator permission (or at least the user login permission) without asking for password? Why native exe can do it and why not .net exe? Should we all move to C++ instead of supporting C#? Any idea? or complains?
-
I have noticed that why anti virus, and other programs can gain administrator access when the app started when computer starts? And why not .net created application? If I set to request administrator level in exe manifest, it will prompt user for permission, and it is very annoying since this application is automatically started at computer startup. How do I gain administrator permission (or at least the user login permission) without asking for password? Why native exe can do it and why not .net exe? Should we all move to C++ instead of supporting C#? Any idea? or complains?
http://www.developerfusion.com/code/7987/making-a-net-app-run-on-vista-with-administrator-priviledges/[^] Check that out.
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
Should run under the the user that started the application.
-
I have noticed that why anti virus, and other programs can gain administrator access when the app started when computer starts? And why not .net created application? If I set to request administrator level in exe manifest, it will prompt user for permission, and it is very annoying since this application is automatically started at computer startup. How do I gain administrator permission (or at least the user login permission) without asking for password? Why native exe can do it and why not .net exe? Should we all move to C++ instead of supporting C#? Any idea? or complains?
It is my understanding that apps like anti-virus programs appear to have admin access from their client tools because they talk to a windows service which is running with elevated privileges. The service is installed when you install the app (which you do get a UAC prompt for) after that point the client tools use IPC to communicate with the privileged service. There may be (and most probably are) exceptions to this rule, I have not done much work in this area. So if your app really needs admin privileges (it probably shouldn’t) a workaround would be to install a windows service which performs the admin functions and communicate with that.
-
It is my understanding that apps like anti-virus programs appear to have admin access from their client tools because they talk to a windows service which is running with elevated privileges. The service is installed when you install the app (which you do get a UAC prompt for) after that point the client tools use IPC to communicate with the privileged service. There may be (and most probably are) exceptions to this rule, I have not done much work in this area. So if your app really needs admin privileges (it probably shouldn’t) a workaround would be to install a windows service which performs the admin functions and communicate with that.
i see, my app is this one Writing a Folder Synchronization application[^] which i think it should have admin privileges, since it is running in background doing synchronization works, which may include synchronizing folder in C or even program files and recently i am having another project, which the application need to configure write its configuration files in its program files folder, but it does not have permission to do so, isn't this weird? for example, what if the application is extendable, where it can download new version or its plugin and put it in it's executable directory, shouldn't it have administrator privileges? Why microsoft need to limit the privileges of executable?
-
i see, my app is this one Writing a Folder Synchronization application[^] which i think it should have admin privileges, since it is running in background doing synchronization works, which may include synchronizing folder in C or even program files and recently i am having another project, which the application need to configure write its configuration files in its program files folder, but it does not have permission to do so, isn't this weird? for example, what if the application is extendable, where it can download new version or its plugin and put it in it's executable directory, shouldn't it have administrator privileges? Why microsoft need to limit the privileges of executable?
John Kenedy S.Kom wrote:
Why microsoft need to limit the privileges of executable?
Any executable runs AS the user that launched it. There are no special restrictions on .EXE's of different types. The "security" model you're assuming is not correct. When you install, say, an anti-virus engine, it installs a service that is actually doing all the work. It usually runs under the Local System account, which has pretty much admin priv's to the entire machine. Any UI program that you use to interact with this anti-virus app always runs as YOU. This app talks to the service and tells the service what it needs to do. The service runs as the local system, giving you the ILLUSION that what you ran has admin priv's.
John Kenedy S.Kom wrote:
for example, what if the application is extendable, where it can download new version or its plugin and put it in it's executable directory
Writing to the Program Files fold is off-limits to normal users, but not admins. But, an .EXE can be installed to other locations that the user CAN write to. All it takes is for the updater to copy down the new .EXE to the correct location, but always the one you think it does. It's also possible that when the app was installed, the security for the apps folder under the Program Files folder was opened up to allow users to write to it. Installers are written to run under administrator accounts, meaning they have free reign to configure the system, security, accounts, ... anything it needs to get the app installed and the rights it needs to do whatever it needs to.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
i see, my app is this one Writing a Folder Synchronization application[^] which i think it should have admin privileges, since it is running in background doing synchronization works, which may include synchronizing folder in C or even program files and recently i am having another project, which the application need to configure write its configuration files in its program files folder, but it does not have permission to do so, isn't this weird? for example, what if the application is extendable, where it can download new version or its plugin and put it in it's executable directory, shouldn't it have administrator privileges? Why microsoft need to limit the privileges of executable?
The synchronization app is exactly the kind of app that should be implemented as a windows service even without the UAC prompting issues. UAC has imposed some architecture changes, configuration files should be place in “Application Settings” directories or isolated storage which are accessible without elevation. Similarly plug-ins can be placed and loaded from those 2 locations. A self updating app could be achieved be installing a basic exe to program files and then loading the bulk of the app code into app settings so it can be replaced if needed or UAC elevation for this feature is completely understandable and the standard practice (Firefox, OpenOffice, etc) all prompt for elevation when updating.
-
John Kenedy S.Kom wrote:
Why microsoft need to limit the privileges of executable?
Any executable runs AS the user that launched it. There are no special restrictions on .EXE's of different types. The "security" model you're assuming is not correct. When you install, say, an anti-virus engine, it installs a service that is actually doing all the work. It usually runs under the Local System account, which has pretty much admin priv's to the entire machine. Any UI program that you use to interact with this anti-virus app always runs as YOU. This app talks to the service and tells the service what it needs to do. The service runs as the local system, giving you the ILLUSION that what you ran has admin priv's.
John Kenedy S.Kom wrote:
for example, what if the application is extendable, where it can download new version or its plugin and put it in it's executable directory
Writing to the Program Files fold is off-limits to normal users, but not admins. But, an .EXE can be installed to other locations that the user CAN write to. All it takes is for the updater to copy down the new .EXE to the correct location, but always the one you think it does. It's also possible that when the app was installed, the security for the apps folder under the Program Files folder was opened up to allow users to write to it. Installers are written to run under administrator accounts, meaning they have free reign to configure the system, security, accounts, ... anything it needs to get the app installed and the rights it needs to do whatever it needs to.
A guide to posting questions on CodeProject[^]
Dave KreskowiakI see, thanks Dave for the answer... Then I might consider to improve my app into a service instead and also learn about IPC, since these two are really new to me. Thanks! Btw, what is the different between Local System account and the admin account? If a user is not an admin and installing the service, can the service then have the admin privileges, such as those own by anti virus?
-
I see, thanks Dave for the answer... Then I might consider to improve my app into a service instead and also learn about IPC, since these two are really new to me. Thanks! Btw, what is the different between Local System account and the admin account? If a user is not an admin and installing the service, can the service then have the admin privileges, such as those own by anti virus?
John Kenedy S.Kom wrote:
If a user is not an admin and installing the service,
If a user is not an admin, they're not installing the service. Also, even if they could, they cannot grant anything more rights than they themselves have. The only accounts that can grant admin permissions, are administrators. The Local System is the account the, well, system uses. Even Windows has to provide credentials to Windows Security.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak