1

I have the following content in a AutoIt file:

#RequireAdmin
Run("start_privileged.bat")

And the batch file contains the following:

@echo off

IF "%PROCESSOR_ARCHITECTURE%" EQU "amd64" (
>nul 2>&1 "%SYSTEMROOT%\SysWOW64\cacls.exe" "%SYSTEMROOT%\SysWOW64\config\system"
) ELSE (
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
)

if '%errorlevel%' NEQ '0' (
echo Requesting administrative privileges...
goto UACPrompt
) else ( goto gotAdmin )

:UACPrompt

    echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
    set params = %*:"=""
    echo UAC.ShellExecute "cmd.exe", "/c ""%~s0"" %params%", "", "runas", 1 >> "%temp%\getadmin.vbs"
    "%temp%\getadmin.vbs"
    del "%temp%\getadmin.vbs"
    exit /B

:gotAdmin
    pushd "%CD%"
    CD /D "%~dp0"

My problem is, that if i execute the AutoIt script, the batch file is called in an endless loop so you will get an epileptical attack. You have to press "X" of the opening CLI really often till the opening windows close. If I start the batch file by just double clicking it, it all works fine.

Do you now, what I have to do, so the scripts opens just ONCE?

Thank you in advance.

Squashman
  • 13,649
  • 5
  • 27
  • 36
marc3l
  • 2,525
  • 7
  • 34
  • 62

2 Answers2

0

The administrator rights request script from OP has known problems and is outdated.

Use this script instead, it is currently working without known bugs:

How to request Administrator access inside a batch file

BUT:

To request admin rights, any batch script needs to run another self-created script, so it might not work with AutoIT. But give it a try and let me know!

Community
  • 1
  • 1
cyberponk
  • 1,585
  • 18
  • 19
0

Good afternoon Marcel,

Try adding an EXIT command to the end of your AutoIt script. I'm currently not on a work computer so I don't have access to administrator to test it.

#RequireAdmin
Run("start_privileged.bat")
EXIT

As simple as this sounds, it should terminate the AutoIt script after it requests admin privileges and runs the batch file. If you're still having issues, let me know. I'm sure we can come up with something to do what you'd like to do.

Thanks,

Tim

Timothy Bomer
  • 504
  • 5
  • 21