1

While I am opening services in C# I am getting User Account Control window. How to send answer[yes/no] to UAC? I do not want to disable UAC.

C# code:

System.Diagnostics.Process.Start("services.msc");
user98891
  • 46
  • 4
  • 3
    Wouldn't that defeat the purpose of the UAC dialog in the first place? Authorizing the application on behalf of the user, without asking the user, is pretty much the same thing as disabling UAC. – David Jan 27 '14 at 15:58
  • I need to send the answer to the UAC from C#. I am wondering if it is even possible. – user98891 Jan 27 '14 at 16:16
  • @user98891 Why do you feel compelled to do this? – David Heffernan Jan 27 '14 at 16:24
  • To the close voters: please read both questions carefully!! – David Heffernan Jan 27 '14 at 17:08
  • In case the question get reopened, you should still consider the duplicate because running as administrator might prevent UAC to pop up. That said, one idea to achieve that will require you to run an aditional process that will move the mouse to `where` the ok button should be. The process then has to click the ok button and die. All you have to do is to detect when the UAC popup shows up. (I don't believe UAC stops every programs and moving the mouse /clicking should be possible) – Loïc Faure-Lacroix Jan 27 '14 at 17:33
  • @Loïc Faure-Lacroix the process cannot move the mouse because uac consent dialog displays on different desktop. Anyway, if you could move the mouse you could click the button without faking input. – David Heffernan Jan 27 '14 at 19:03
  • @DavidHeffernan Is it possible to run a service in the UAC desktop session that could move the mouse? Yes I know this is pointless and circumvents the whole purpose of UAC, but it's a thought experiment. :) – dss539 Jan 27 '14 at 20:46
  • @dss539 You wouldn't move the mouse. You'd just click the button. And what about over-the-shoulder consent for standard user? I expect it could be done but it would require hacking. – David Heffernan Jan 27 '14 at 20:50
  • @DavidHeffernan Any idea how to hack this? – user98891 Jan 28 '14 at 19:30
  • I think I answered the question that you asked. – David Heffernan Jan 28 '14 at 19:39

1 Answers1

2

The simple answer is that you are not allowed to do that. If you were, that would pretty much defeat the purpose of UAC. The UAC consent dialog is shown on a different desktop, the secure desktop, and as such your program cannot communicate with it.

I don't expect you will be pleased to hear this news. Perhaps there is a different solution to your underlying problem, but handling the consent dialog on behalf of the user is not it.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490