Avatar ·

How to make a .NET application run as administrator?

Hello everyone! I'm writing a small C# (Windows Forms) application that needs to edit system files and registry keys. The problem is that when running normally, the program works fine, but as soon as it tries to write to Program Files or change system settings, it throws a System.UnauthorizedAccessException.\n\nI understand that the application needs to run with elevated privileges, but how can I do this programmatically? I tried adding a manifest, but Visual Studio complains. I've seen on forums that you can use administrator rights via app.manifest, but I don't have this file in my project.\n\nHere's an example of code that tries to write a log to a protected folder:\n\n```csharp\nusing System;\nusing System.IO;\n\nclass Program\n{\n static void Main()\n {\n string pa