1

I ran this batch file:

:START
FOR /f "tokens=2 delims=," %%a in ('typeperf "\processor(_Total)\%% Processor Time" -SC 1 -y ^|find ":" ') DO
(set "var=%%~na"
IF var>=30
(netsh interface teredo set state disabled
netsh interface 6to4 set state disabled
netsh interface isatap set state disabled )
IF var<30
( netsh interface teredo set state client
netsh interface 6to4 set state enabled
netsh interface isatap set state enabled
) )
goto START

I want that this program continuosly scans CPU usage percentage, and store that value in an integer 'var'.

Now if CPU usage is more than 30%, I want to disable IPv6. If CPU usage come down to 30%, I want to enable IPv6. I wrote above code, but it is not working. Can you say where is the problem.

Steve-o
  • 12,678
  • 2
  • 41
  • 60
Rock smith
  • 11
  • 3
  • what do you mean by disable `IPV6` - for a particular network card?I dont think `netsh interface 6to4 set state disabled` is exactly disabling. – npocmaka Sep 07 '14 at 14:41

2 Answers2

0

If your netsh commands are correct then this may work for you:

@echo off
:START
FOR /f "tokens=2 delims=," %%a in ('typeperf "\processor(_Total)\%% Processor Time" -SC 1 -y ^|find ":" ') DO (
echo CPU is at %%a %%
   IF %%~na GTR 30 (
      echo disabling
      netsh interface teredo set state disabled
      netsh interface 6to4 set state disabled
      netsh interface isatap set state disabled 
   ) else (
      echo enabling
      netsh interface teredo set state client
      netsh interface 6to4 set state enabled
      netsh interface isatap set state enabled
   )
)
echo waiting
timeout /t 5 /nobreak >nul
goto :START
foxidrive
  • 40,353
  • 10
  • 53
  • 68
0

One more way - with LOGMAN which relies on same counters as typeperf.

With this approach you'll no need of running/looping batch file - after the code bellow is finished the tasks will start autocratically.

But you'll need to create two additional .bat files to enable and disable IPv6 (in this example disable6.bat and enable6.bat).Or at least one additional bat that accepts arguments and use -targ key of logman (both LOGMAN and SCHTASKS require admin permissions):

@echo off


SCHTASKS /create /tn disable /tr "C:\disable.bat" /sc ONCE /sd 01/01/1910 /st 00:00 
logman stop high_cpu 2>nul & logman delete high_cpu 
logman create alert high_cpu -th "\Processor(_Total)\%% Processor Time>30" -tn "disable"
logman start high_cpu



SCHTASKS /create /tn enable /tr "C:\enable6.bat" /sc ONCE /sd 01/01/1910 /st 00:00
logman stop low_cpu 2>nul & logman delete low_cpu 2>nul  
logman create alert low_cpu -th "\Processor(_Total)\%% Processor Time<30" -tn "enable" 
logman start low_cpu

check also NSPBIND tool for disabling IPv6.

npocmaka
  • 55,367
  • 18
  • 148
  • 187