0

Yesterday I asked a question on a Java Runtime. I resolved it myself, but now I'm insterested to don't show UAC prompt when I start my program. This program is an exe and it has the Administrator manifest.

Code :

Runtime.getRuntime().exec("cmd /c \"C:\\Program Files (x86)\\CodFiscExtractor\\MySQLServer\\MySqlStart.exe\"");

With this I start my program, but, how I said before, it displays me the uac prompt.

What I should do?

Gabriel
  • 464
  • 4
  • 17

2 Answers2

2

If the program that you start through your program requires administrator privileges the UAC prompt will show up. That's pretty much the reason for the UAC prompt!
If you start your program as Administrator, you should be able to execute stuff with Admin privileges (that is, without UAC), but there will always be a prompt at one place or another (as long as the UAC is not turned off).

Jite
  • 5,761
  • 2
  • 23
  • 37
  • There is a method to start the program as administrator without showing the uac prompt? – Gabriel Apr 24 '18 at 14:40
  • No, not if the user have not set UAC to off. The reason for UAC is to protect users from programs to temper with stuff that they are not supposed to, so when the UAC prompt shows up, the user either allow or deny the program access to admin privileges. There is rarely a need to "disable" the UAC if there is no malicious intent though, so just let it pop up. :) – Jite Apr 24 '18 at 14:48
  • So, is virtually **impossible** to don't show uac? Not even with something just like a bat? – Gabriel Apr 24 '18 at 14:50
  • 1
    No, if you need admin privileges (which starting the mysql service does), the UAC prompt will show up as long as the user have not turned it off. – Jite Apr 24 '18 at 14:51
  • It is not impossible to prevent the UAC dialog from appearing. You just need to apply the correct manifest to tell windows "I don't do anything I shouldn't." This may help. https://stackoverflow.com/questions/24777660/ – killjoy Apr 24 '18 at 14:57
  • @killjoy, well, the UAC should still show up when executing stuff that requires admin privileges as in the question, should it not? – Jite Apr 24 '18 at 14:59
  • @Jite Yes, but it shouldn't prompt you until it actually does it. If your program doesn't do anything that requires admin, it will never prompt. – killjoy Apr 24 '18 at 15:00
  • Well of course, but you need no manifest for that do you? In the question above, the application will access a resource which requires admin elevation/privileges, hence the UAC prompt will have to show up at one or another point. – Jite Apr 24 '18 at 15:01
  • This may also help. https://msdn.microsoft.com/en-us/library/windows/desktop/aa374191(v=vs.85).aspx – killjoy Apr 24 '18 at 15:01
  • @Jite Is it? The way I understand it, the question was about running a java program compiled to an exe using a program like launch4j. Through experience, I've found that it likes to use admin access by default when running programs created with it. – killjoy Apr 24 '18 at 15:02
  • Well yes, please read the question again, OP want to avoid getting the UAC prompt when executing the following code: `Runtime.getRuntime().exec("cmd /c \"C:\\Program Files (x86)\\CodFiscExtractor\\MySQLServer\\MySqlStart.exe\"");` – Jite Apr 24 '18 at 15:04
1

You cannot. This is controlled by Windows at the OS level. UAC would have zero point if programs could simply avoid it.

Either write a program that doesn't call executables, or accept that UAC will trigger. That's not your choice.

SpacePrez
  • 1,086
  • 7
  • 15