سؤال

In have an application where i want to start an install of another program and the user must be administrator. To do this i do the following:

var info = new ProcessStartInfo();

info.FileName = fileName;
info.Verb = "runas";
info.UseShellExecute = false;

Process.Start(info);

This works fine except that the user must be administrator and the prompt for UAC does not show up. I have read that Verb should be "runas" and UseShellExecute should be false. But it does simply not work. Any ideas why? :)

هل كانت مفيدة؟

المحلول

The use of the runas verb only works when UseShellExecute is true. That's because the Verb only has meaning when the ShellExecuteEx API is called.

In your code, the underlying API that is used is CreateProcess, and that does not receive a verb, and so your specification of runas is simply ignored.


That's the answer to the question that you asked, but I suspect that your chosen solution is not the best. If the install program always needs to run elevated, then you should mark it as such. When you make the install program, use the requireAdministrator option in the manifest file. That way the UAC elevation process will be invoked whenever the install program is run. This puts the knowledge of the need to elevate into the installation program rather than the invoking program which is really the right place for it.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top