How to start a Process as administrator mode in C
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
In C#, the usual way to start a process with administrator privileges is to use ProcessStartInfo with UseShellExecute = true and Verb = "runas". That tells Windows to launch the process through the shell and show the normal User Account Control elevation prompt if required.
Start the Process with runas
This is the core pattern:
If the current user approves the prompt, the process starts elevated. If the user cancels it, process creation fails.
Pass Arguments and a Target Executable
You can start your own executable with arguments the same way:
The important setting is still UseShellExecute = true. Without that, the Verb is ignored and Windows will not perform shell-based elevation.
Handle User Cancellation Cleanly
Elevation can fail for legitimate reasons, especially when the user clicks "No" in the User Account Control dialog. Catch that case explicitly:
That avoids an unhelpful crash when elevation is denied.
Understand What Elevation Does Not Do
Starting a child process as administrator does not retroactively elevate your current process. Your current application stays at its original privilege level unless it was itself launched with elevation.
That matters when developers expect one elevated helper process to somehow grant admin rights back to the parent. Windows does not work that way. If the current app needs elevated behavior for its own operations, it must be launched accordingly or declare the requirement in its manifest.
Consider Whether You Need Elevation at All
Elevation should be the exception, not the default. Use it only for operations that genuinely require administrator access, such as writing to protected locations, editing system settings, or installing software.
If only one step requires elevated access, a good design is to keep the main application unelevated and launch a focused helper process with runas for that step. That reduces risk and keeps the normal UX cleaner.
Use a Manifest Only When the Whole App Must Elevate
If your application always needs administrator rights, another option is an application manifest with a requested execution level. That changes the elevation model for the whole app, whereas Verb = "runas" is better when you only need to elevate a specific child process occasionally.
Common Pitfalls
- Forgetting
UseShellExecute = true. Without it,Verb = "runas"does not trigger shell elevation. - Assuming the current process becomes elevated after launching one child process as administrator. Elevation applies only to the new process.
- Not handling
Win32Exceptionwhen the user cancels the UAC prompt. - Elevating every launch by default when only a small subset of tasks actually needs admin rights.
- Passing a file path or arguments incorrectly and then blaming elevation. Always verify the target executable and argument string first.
Summary
- In C#, start an elevated process with
ProcessStartInfo,UseShellExecute = true, andVerb = "runas". - Use the pattern for a specific executable and optional arguments.
- Catch cancellation errors so the app fails gracefully when UAC is denied.
- Remember that only the child process becomes elevated.
- Request administrator privileges only for operations that truly need them.
Related reading
- How to start an async method without await its completion?
- How to stop BackgroundWorker correctly
- How to stop BackgroundWorker on Form's Closing event?
- How to store data locally in .NET C
- How to store images using Entity Framework Code First CTP 5?
- How to take all but the last element in a sequence using LINQ?
- How to tell Json.Net globally to apply the StringEnumConverter to all enums
- How to terminate a thread in C?

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.