I am running a process from a vbsscript and I want it to run indefinitely in the background. It works as expected for a while and shuts itself off. If I open the batch file directly it won't stop at all which is the behavior I want, but in the background. This is the code I use to make it run.
Dim WinScriptHost
Set WinScriptHost = CreateObject("WScript.Shell")
WinScriptHost.Run Chr(34) & "C:\hackish\beHackish.bat" & Chr(34), 0
Set WinScriptHost = Nothing
*Edit I thought I might have more luck if I added the script.
@ECHO OFF
taskkill /IM explorer.exe /F
Start loadAliases.bat
setlocal
set multipleNotification=3
set BatteryLevel=-1
set notificationThreshold=15
set hasBatteryNotified=0
set cycleLen=6
set alternator=0
:: increment length bc of division
set cycleLen=%cycleLen%+1
:LOOP
:: pausing
TIMEOUT /T 1 /NOBREAK > nul
:: if on battery
for /F "delims== tokens=1,2" %%a in ('WMIC Path Win32_Battery Get BatteryStatus /format:textvaluelist.xsl') do @if "BatteryStatus"=="%%a" call :BATUPDATE "%%b"
:BATUPDATE
set /a alternator=!%alternator%
if %~1 NEQ 2 (
goto DISCHARGING
) else (
goto CHARGING
)
:CONTINUE3
:: check custom hotkey (bc windows doesn't work right)
keyCheck\isKeyDown.exe 11
IF errorlevel 1 GOTO CHECKT
GOTO LOOP
:CHECKT
keyCheck\isKeyDown.exe 09
IF errorlevel 1 Start loadAliases.bat
GOTO LOOP
:DISCHARGING
echo discharging
:: if battery level low, notify
for /f %%a in ('wmic.exe path Win32_Battery get EstimatedChargeRemaining ^| findstr.exe /r "[0-9][0-9]*"') do set BatteryLevel=%%a
set /a notMultiple = %BatteryLevel% %% %multipleNotification%
if %BatteryLevel% leq %notificationThreshold% if %notMultiple% == 0 (
:: if not notified
if %hasBatteryNotified% == 0 (
start cmd /K echo Batery is at %BatteryLevel%!!
set hasBatteryNotified=1
)
) else (
set hasBatteryNotified=0
)
:: update wallpaper cycle
set /a num = 100 / %cycleLen%
set /a num = %BatteryLevel% / num
SET wallPath="C:\\hackish\desktops\pics\0%num%%alternator%.bmp"
desktops\Project1.exe %wallPath%
GOTO CONTINUE3
:CHARGING
echo charging
set hasBatteryNotified=0
:: update wallpaper cycle
for /f %%a in ('wmic.exe path Win32_Battery get EstimatedChargeRemaining ^| findstr.exe /r "[0-9][0-9]*"') do set BatteryLevel=%%a
set /a num = 100 / %cycleLen%
set /a num = %BatteryLevel% / num
SET wallPath="C:\\hackish\desktops\pics\1%num%%alternator%.bmp"
desktops\Project1.exe %wallPath%
GOTO CONTINUE3
*Edit 2 Logging produced the issue
for /F "delims== tokens=1,2" %%a in ('WMIC Path Win32_Battery Get
BatteryStatus /format:textvaluelist.xsl') do @if "BatteryStatus"=="%%a" call :BATUPDATE "%%b"
This eventually causes problems on the stack which are explained nicely here: http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/Q_27500205.html I'll be working on a solution for my case which does not require the overhead of re-executing a new batch file instead of looping-- if that does cause additional overhead as I believe it would. If someone beats me to it that'd be great though. ^.^