Question How do I run c# application as administrator in start up

Kamen

Active member
Joined
Nov 30, 2020
Messages
28
Programming Experience
1-3
I'd run my c# application as administrator in startup. So I added some codes for this and I can see app name in startup list but it does not work when starting OS really. If I set my c# app's excutionLevel as asInvoker in app.manifest, it is working well but not work for the requireAdministrator.
Have you any other good idea?
I hope you help me asap.
Best Regards.
 
Solution
You can read from Program Files without admin rights.

You can change Time Zones without being an admin. Do you really need to change the time when modern Windows actually synchronizes itself with NTP servers which use atomic clocks to keep time?

The correct thing to do is to get the UAC only at the time when you are trying to do something that actually requires admin rights, at the time when you need it. You don't want to always be running as admin. By always running as admin, you open up the attack surface for viruses. A virus will just have to inject itself into app instead of trying to inject itself into other more will known apps/processes which are more actively monitored by AV software and/or Windows Defender.

Please follow...
Why does your app need to run an administrator at all? Windows has been discouraging app developers from making their apps run with administrator rights ever since the Slammer virus practically crippled Microsoft in 2003.

If you must absolutely run with admin rights, make your application a Windows service instead of an application. You can setup the service to run as System.
 
The problem you appear to be facing (assuming I understand you want your app to run as admin on windows start up?) - is that this action requires the users interaction to start on prompt. I assume you want it to start silently and as admin?

If so, can you first explain why you need these permissions?
 
Task Scheduler will allow you to do that. Use "Run with highest privileges" option and specify to run as an admin user account.
 
The problem you appear to be facing (assuming I understand you want your app to run as admin on windows start up?) - is that this action requires the users interaction to start on prompt. I assume you want it to start silently and as admin?

If so, can you first explain why you need these permissions?
Hello, Thanks for your attention.
This app should be made for that it could write and read file on c:/program files folder and can control windows system settings such as date and time. From several experiments, I think it must have admin right to do it.
It is the reason that my app needs admin permission.
So I updated app.manifest file to get administrator privilleages and as a result app is working well for this but don't prompt when OS starting.
This is my current case.
Thank you again.
Best regards.
 
You can read from Program Files without admin rights.

You can change Time Zones without being an admin. Do you really need to change the time when modern Windows actually synchronizes itself with NTP servers which use atomic clocks to keep time?

The correct thing to do is to get the UAC only at the time when you are trying to do something that actually requires admin rights, at the time when you need it. You don't want to always be running as admin. By always running as admin, you open up the attack surface for viruses. A virus will just have to inject itself into app instead of trying to inject itself into other more will known apps/processes which are more actively monitored by AV software and/or Windows Defender.

Please follow the Windows Guidelines with regards to UAC:
 
Solution
Back
Top Bottom