How to self elevate the bat file with auto select the UAC prompt with [ok] option.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
KSKwin123
Posts: 4
Joined: 21 Dec 2021 23:12

How to self elevate the bat file with auto select the UAC prompt with [ok] option.

#1 Post by KSKwin123 » 04 Sep 2022 19:05

I have a below batch file as conf.bat
Rem Batch file starts
ipconfig /release
ipconfig /renew
ipconfig /flushdns
ipconfig /registerdns
Rem Batch file ends.

Here, the command prompt display with “The requested operation requires elevation” for (ipconfig/registerdns).
I want to self elevate bat file and to auto select the [ok] button for UAC prompt for this batch file {conf.bat].
Pl. help.

— KSKwin

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: How to self elevate the bat file with auto select the UAC prompt with [ok] option.

#2 Post by aGerman » 05 Sep 2022 10:04

Batch doesn't interact with graphical user interfaces. Something like keyboard and mouse emulation is just not foreseen. Besides of that I suspect that the UAC prompt is secured against automation like that.

However, you might be able to work around it like that:
- Create a scheduled task with "Run with highest privileges" checked. No trigger necessary. "Action" is C\Windows\System32\cmd.exe for the program, and /c ""C:\wherever\some.bat"" for the argument.
- Run this task from within a batch script using the SCHTASKS command.

Steffen

Post Reply