1. Create List of All Running Processes
2. Identify number of lines in final output list of step 1. Need to because this helps how many times my for loops later in script runs.
3. Create a separate list of processes & PIDs only.
4. Combine what is found in step 3, a list of both Processes and PIDs only.
5. Find executable path of Running Process, where the processes were identified in step 3
6. Now, need to combine what was generated in Step4 and Step5
for example in step 6, need to display the following:
Process Name PID #
==========================================
executable path information which step number 5 produced.
==========================================
I had examined my code and didn't like how it was written.
I still get this error occuring when I run the script:
Missing operator.
Missing operator.
but, after correcting and changing the script, I had documented each section as to what occurs and purpose, hopefully it will be clearer.
I would be a bonus if I could figure out how to extract and and keep path information.
For example, if I have a path with a file name, C:\Windows\System32\smss.exe
I would like to get smss.exe stripped from the path and take the path " C:\Windows\System32\ " and simply place it into a variable for later processing.
such as . . . <a href="%%c">Process Name</a>
Process Name PID #
==========================================
executable path information which step number 5 produced.
==========================================
will, by the time the code zips along to all the routines, when it comes to identifying the process executable path, it's rather slow. When I run my script on my immediate workstation that has a raid 0 solid state drives, it's abit faster, but slow.
Just looking to get help to complete Step #6 to get the data to a good text file, that I can then continue to work on the html coding myself. Just need to figure out how to get the the process name, pid num and executable path. My initial script was to create a compound for loop ( 2 for loops) to combine and place the needed data into text file for later processing to html. I ask for no fancy but basic understanding on how to do that; just simply stuck.
I appreciate all the help. I've posted my code below here, just need to copy/paste the code into a batch file w/in the temp1 subfolder on c: drive. Best Regards, booga73
Code: Select all
@ECHO OFF
cd\
c:
cd temp1
cls
:: 1.
:: Beginning of Task 1 Create List of All Running Processes & PIDS.
:: The Processes & PIDS reside in column 1 (processes) & Column 2 (PIDS) in tsklst2.txt
:: the tsklst2.txt will show all the running processes and pid number associated to each process
:: *************************************
tasklist > c:\temp1\tsklst1.txt
more +4 c:\temp1\tsklst1.txt > c:\temp1\tsklst2.txt
erase /s /q c:\temp1\tsklst1.txt
cls
:: *************************************
:: End of Task 1 Create List of All Running Processes & PIDs
:: 2
:: code start to identify number of lines in a text & hold value in LineNumb
:: *************************************
SETLOCAL
Set FileName=tsklst2.txt
Set /a LineNumb=0
for /f "tokens=*" %%a in ('find /c /v "" %FileName%') do set /a LineNumb=%%a
ENDLOCAL
:: *************************************
:: code end to identify number of lines in a text
:: 3
:: beginning of code to read all tokens in column 1 & 2 of tsklst2.txt
:: ProNme1.txt shows the unique processes on the computer
:: PID#.txt shows the unique processor identification of each process
:: *************************************
SETLOCAL
for /F "tokens=1" %%a in (c:\temp1\tsklst2.txt) do (
echo %%a >> c:\temp1\ProNme1.txt
)
ENDLOCAL
SETLOCAL
for /F "tokens=2" %%a in (c:\temp1\tsklst2.txt) do (
echo %%a >> c:\temp1\PID#.txt
)
ENDLOCAL
:: *************************************
:: end of code to read all tokens in column 1 & 2 of tsklst2.txt
:: 4
:: Beginning, this code here takes all the tokens from both ProNme1.txt and PID#.txt and places them into ProAnPid.txt
:: *************************************
setLocal enableDELAYedeXpansion
set N=
for /f "tokens=* delims= " %%a in (c:\temp1\PID#.txt) do (
set /a N+=1
set M!N!=%%a
)
set N=
for /f "tokens=* delims= " %%a in (c:\temp1\ProNme1.txt) do (
set /a N+=1
set I!N!=%%a
)
for /L %%i in (1 1 !N!) do (
>> c:\temp1\ProAnPid.txt echo.!I%%i!!M%%i!
)
ENDLOCAL
:: erase /s /q c:\temp1\ProNme1.txt
:: erase /s /q c:\temp1\PID#.txt
:: *************************************
:: End, this code here takes all the tokens from both ProNme1.txt & PID#.txt and places them into Pro&Pid.txt
:: 5
:: Find executable path of Running Process
:: Beginning code to identify path of running process
:: dir /b /s is the command that processes and finds the path of the running process
:: *************************************
:: this code verifies that when processing this ExeCute code, dir /b /s needs to be run from the root of drive c:
:: ----------------------------
c:
cd\
:: ----------------------------
set num=
set num=%%b
SETLOCAL
SET /A maxlines=!LineNumb!
SET /A linecount=0
FOR /F "tokens=*" %%b IN (c:\temp1\ProNme1.txt) DO (
echo ========================================== >> c:\temp1\ExeCute.txt
dir /b /s %num% >> c:\temp1\ExeCute.txt
echo ========================================== >> c:\temp1\ExeCute.txt
echo. >> c:\temp1\ExeCute.txt
echo. >> c:\temp1\ExeCute.txt
IF !linecount! EQU %maxlines% GOTO ExitLoop
SET /A linecount+=1
)
:ExitLoop
ENDLOCAL
:: *************************************
:: End code to identify path of running process
pause
exit