title: For Loop High CSRSS CPU
body: <p>I have a batch file that takes an input file (in this case the file is a flat text file comprised of a file listing from a specified set of Windows XP system directories).  </p>
  
  <p>Then through a combination of a for loop to iterate through each file listed in the text file), setting a variable, using several call commands (in this case 9), and the find command to search the text file for files that appear in the output of other flat files.  </p>
  
  <p>The problem I am running into is that csrss.exe is using quite a bit of CPU processing.  In reading some other articles it seems that csrss has a relationship with command line processing.  </p>
  
  <p>What I want to know is if there is a better way to do this that will:</p>
  
  <ol>
  <li>Reduce overall script time.</li>
  <li>Reduce CPU load.</li>
  </ol>
  
  <p>Below is a sample of the script:</p>
  
  <pre><code>:: ------------------------------------------------------
  ::  Running Multiple Commands
  :: ------------------------------------------------------
  
  for /f "delims=?" %%A in (dir-selected_tmp.txt) do (  
  set filepath=%%A  
  call :filepathparse  
  call :md5hashchk  
  call :versionchk  
  call :densitychk  
  call :processchk  
  call :mutexchk  
  call :networkchk  
  call :injectedchk  
  call :persistservicechk  
  call :servicedllchk  
  call :persistrunchk  
  call :persistothchk  
  call :unsigneddllchk  
  call :filesysag  
  )  
  goto :comparison  
  
  :: ####################################################################
  
  :filepathparse
  for %%B in ("%filepath%") do (
  set filename=%%~nxB
  )
  goto :eof
  
  :: ####################################################################
  
  :md5hashchk
  
  for /f "delims= " %%b in ('md5deep.exe "%filepath%"') do set hashvalue=%%b
  goto :eof
  
  :: ####################################################################
  
  :versionchk
  
  for /f "delims= " %%e in ('sigcheck.exe /accepteula -q -n "%filepath%"') do set versionvalue=%%e
  goto :eof
  
  :: ####################################################################
  
  :densitychk
  
  for /f "delims= " %%d in ('densityscout.exe -p 0.1 "%filepath%"') do set densityvalue=%%d
  goto :eof
  
  :: ####################################################################
  
  :processchk
  
  find.exe /I "%filepath%" %temp_outpath%\wmic-processes.txt &gt; nul 2&gt;&amp;1 &amp;&amp; goto processexist
  set isprocess=NoActiveProc
  goto :eof
  
  :processexist
  set isprocess=ActiveProc
  goto :eof
  
  :: ####################################################################
  
  :mutexchk
  
  if "%startup_chk%"=="-b" (
  goto :mutexbl
  )       
  
  find.exe /I "%filepath%" %temp_outpath%\filesystem-handles_compared.txt &gt; nul 2&gt;&amp;1 &amp;&amp; goto mutexexist
  set ismutex=NoNewActiveMutex
  goto :eof   
  
  :mutexexist
  set ismutex=NewActiveMutex
  goto :eof
  
  :mutexbl
  
  find.exe /I "%filepath%" %parsed_outpath%\filesystem-handles.txt &gt; nul 2&gt;&amp;1 &amp;&amp; goto mutexexist
  set ismutex=NoNewActiveMutex
  goto :eof   
  
  :mutexexist
  set ismutex=NewActiveMutex
  goto :eof
  
  :: ####################################################################
  
  :networkchk
  
  find.exe /I "%filename%" %temp_outpath%\tcpvcon_tmp.txt &gt; nul 2&gt;&amp;1 &amp;&amp; goto networkexist
  set isnetwork=NoActiveNetwork
  goto :eof
  
  :networkexist
  set isnetwork=ActiveNetwork
  goto :eof
  
  :: ####################################################################
  
  :injectedchk
  
  find.exe /I "%filepath%" %temp_outpath%\injecteddll_tmp.txt &gt; nul 2&gt;&amp;1 &amp;&amp; goto injectedexist
  set isinjected=NoActiveInject
  goto :eof
  
  :injectedexist
  set isinjected=ActiveInject
  goto :eof
  
  :: ####################################################################
  
  :persistservicechk
  
  find.exe /I "%filepath%" %temp_outpath%\autoruns-services_tmp.txt &gt; nul 2&gt;&amp;1 &amp;&amp; goto serviceexist
  set isservice=NoInstalledService
  goto :eof
  
  :serviceexist
  set isservice=InstalledService
  goto :eof
  
  :: ####################################################################
  
  :servicedllchk
  find.exe /I "%filepath%" %temp_outpath%\registry_hklm_installed_service_dlls_final.txt &gt; nul 2&gt;&amp;1 &amp;&amp; goto servicedllexist
  set isservicedll=NoInstalledServiceDLL
  goto :eof
  
  :servicedllexist
  set isservicedll=InstalledServiceDLL
  goto :eof
  
  :: ####################################################################
  
  :persistrunchk
  
  find.exe /I "%filepath%" %temp_outpath%\autoruns-run_tmp.txt &gt; nul 2&gt;&amp;1 &amp;&amp; goto runpersistexist
  set isrunpersist=NoRunPersist
  goto :eof
  
  :runpersistexist
  set isrunpersist=RunPersist
  goto :eof
  
  :: ####################################################################
  
  :persistothchk
  
  find.exe /I "%filepath%" %temp_outpath%\autoruns-oth_tmp5.txt &gt; nul 2&gt;&amp;1 &amp;&amp; goto persistothexist
  set isothpersist=NoOtherPersist
  goto :eof
  
  :persistothexist
  set ispersist=OtherPersist
  goto :eof
  
  :: ####################################################################
  
  :unsigneddllchk
  
  find.exe /I "%filepath%" %temp_outpath%\listdlls_temp2.txt &gt; nul 2&gt;&amp;1 &amp;&amp; goto unsigneddllexist
  set isunsigneddll=NoUnSignedProcDLL
  goto :eof
  
  :unsigneddllexist
  set isunsigneddll=UnSignedProcDLL
  goto :eof
  
  :: ####################################################################
  
  :filesysag
  
  :: Compiling Into Syslog Format 
  
   echo %datestamp%^|%currtime%^|%computername%^|%currip%^|%username%^|%lastlogintime%^|"%filepath%"^|%hashvalue%^|%versionvalue%^|%densityvalue%^|%isprocess%^|%ismutex%^|%isnetwork%^|%isinjected%^|%isservice%^|%isservicedll%^|%isrunpersist%^|%isothpersist%^|%isunsigneddll% &gt;&gt; %syslog_outpath%\%computername%-syslog.txt
  
   :: Compiling Into Parsed Format
  
  echo "%filepath%"^|%hashvalue%^|%versionvalue%^|%densityvalue%^|%isprocess%^|%ismutex%^|%isnetwork%^|%isinjected%^|%isservice%^|%isservicedll%^|%isrunpersist%^|%isothpersist%^|%isunsigneddll% &gt;&gt; %parsed_outpath%\%computername%-filesystem.txt
  goto :eof
  </code></pre>