0

I have an application(called 'Launcher'), where i can start other applications

One of this applications needs administrator-rights. If i try to launch it from the Launcher i get an exception, which says that i need higher privilege.

The code to start an application from the Launcher looks like:

try
{
   ProcessStartInfo startInfo = new ProcessStartInfo(PATH, ARGUMENT)
      {
         WorkingDirectory = WORKINGDIRECTORY
      };
   Process.Start(startInfo);
}
catch(Exception ex)
{
   MessageBox.Show(ex.Message);
}

If I start the Launcher everything works fine. But I don't want to start the Launcher as administrator every time.

How can I start the new process as administrator from a non-admin-process?

Tomtom
  • 9,087
  • 7
  • 52
  • 95

2 Answers2

0

Your application needs to be admin or you need to provide a username password. For the username/password approach see:

https://groups.google.com/forum/?fromgroups=#!msg/microsoft.public.dotnet.languages.csharp/u5YuEz416R8/1oTRvUUzKj4J

And this has more of an approach you are looking for, but it's not a nice small snippet of code as you may like.

Process.Start with different credentials with UAC on

Otherwise, add this to your app manifest file.

 <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
Community
  • 1
  • 1
corylulu
  • 3,449
  • 1
  • 19
  • 35
  • But i don't want to run the Launcher always as administrator. – Tomtom Feb 28 '13 at 09:22
  • For security reasons, you can't do that without providing the username and password to the admin account. Only if the original application is admin can you use the runas verb. – corylulu Feb 28 '13 at 09:27
  • I thought it would be possible to start the other application as adminsitrator and then the uac-message appears? – Tomtom Feb 28 '13 at 09:30
  • Check my edited post. I posted links on alternative methods of doing this. None of them are very pretty though. – corylulu Feb 28 '13 at 09:31
0

Create an account with admin rights and then populate the UserName and Password properties on the ProcessStartInfo instance with the corresponding values for the admin account.

Sean
  • 60,939
  • 11
  • 97
  • 136