Check UAC Status

As a script, a batch file that will check if UAC is enabled:

REG QUERY HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System\ /v EnableLUA 

It is included if the result:

 HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System EnableLUA REG_DWORD **0x1**) 

and it is disabled if the result:

 HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System EnableLUA REG_DWORD **0x0**) 

The script should run different commands according to the result.

+4
source share
1 answer

You can simply search for one or the other value with FIND or FINDSTR and invoke commands depending on the search result. The template will look like this:

 REG QUERY HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System\ /v EnableLUA | ( FIND "0x1" >NUL ) && ( command(s)_to_run_when_UAC_is_enabled ) || ( command(s)_to_run_when_UAC_is_disabled ) 

those. REG produces an output signal that is passed using pipe ( | ) to the FIND input. FIND searches for 0x1 at its input and, depending on the search result, one of the following blocks of commands enclosed in parentheses is executed.

command && command || command command && command || command is a standard mechanism that allows you to selectively run commands, something like replacing IF . The first command gives the result. The command immediately after && starts if the result is โ€œsuccessโ€ and the team immediately after || starts in case of failure.

If you need to perform actions in both cases, use both && and || after the command generating the result, but if you need to respond to only one type of result, you can leave either && or || .

+1
source

All Articles