I am trying to change out my hosts file based on whichever environment I run my script in. It looks like what I'm needing to do is run the commands as admin (elevated privileges), I just cannot seem to find out how to do that in AutoIT.
Here is an example of the call from Selenium:
Runtime.getRuntime().exec("C:\HostSwitcher.exe " + C:\Scripts + " " + "QA2");
$filePath = $CmdLine
$env = $CmdLine
Run(@comspec & " /c DEL %WINDIR%\SYSTEM32\DRIVERS\ETC\HOSTS")
if $env = "Dev" then
Run(@comspec & " /c COPY "&$filePath&"hostFiles\DevHost.txt %WINDIR%\SYSTEM32\DRIVERS\ETC\hosts")
if $env = "QA2" then
Run(@comspec & " /c COPY "&$filePath&"hostFiles\QA2Host.txt %WINDIR%\SYSTEM32\DRIVERS\ETC\hosts")
As a starting note, your account should have elevated privileges.
As far as I know you have options here:
the most desired and safe one
Run your Java application (IntelliJ, Eclipse) as Administrator. This way, any processes spawn or executed by it would be ran with elevated privileges (this works as a chain reaction in Windows and not only).
Run it with elevated privileges
Runtime.getRuntime().exec("runas /profile /user:Administrator \"C:\HostSwitcher.exe " + C:\Scripts + " " + "QA2");