I've spent the last I don't even know how long troubleshooting this, and I finally found it out. I've been trying to run this line of code:
system("C:\\Users\\Public\\automate.bat");
But instead of executing the script once, it repeatedly executed the first line of my script (in an infinite loop). I found that the path it was using for windows CMD was C:\Windows\SysWOW64\cmd.exe while the windows default is C:\Windows\System32\cmd.exe. I went to the SysWOW cmd and ran my script and the looping issue happened, while the same script worked flawlessly on the System32 CMD. (I suspect because of some incompatibility in my code that caused the SysWOW cmd to fail). I would like to know how to change the cmd.exe path on C so that it points to windows' default cmd, and not the one in SysWOW.
Currently, the only thing I've tried is:
system("C:\\Windows\\System32\\cmd.exe /c C:\\Users\\Public\\automate.bat");
Which is not working.
EDIT: The first action of my BAT file is to ask for administrator perms, which is where the window seems to close, and reopen itself:
@echo off
:: BatchGotAdmin
:-------------------------------------
REM --> Check for permissions
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"
)
REM --> If error flag set, we do not have admin.
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"
:--------------------------------------
cd "C:\Users\Public"
:: more stuff here