Hey I am trying to learn some basic .bat programming and haven't had any luck with google.
I am using a windows 7 pc and this is what I am trying to do:
Create a program that looks at the current tasks using tasklist.
Saves the list to a file
Reads the file into an array
opens a browser (chrome/ie/w/e)
loads task list into a new file
compare the 2 files to find the new PID
end that PID
so basically the program opens a new window and only closes that window.
Any help would be appreciated I have been trying to do arrays to store the file and have had issues.
This is not a homework assignment or anything like that just trying to get familiar with batch because I think its useful so feel free to change what the program does to accomplish the task or just help with general arrays.
PS. I am familiar with C#, C++, C, Java, and Python along with many other random languages so if you compare batch to one of them i'll understand.
Thanks
Learning .bat
Moderator: DosItHelp
Re: Learning .bat
Comparing two outputs of Tasklist and using pseudo arrays seems kind of overkill for what you want to do.
Re: Learning .bat
You could use WMIC to create a process. Simply extract the PID from its output.
This example opens its own code in notepad and closes the notepad instance after a 5 seconds delay ...
Regards
aGerman
EDIT replaced outer double quotes with single quotes for the expression next to create
This example opens its own code in notepad and closes the notepad instance after a 5 seconds delay ...
Code: Select all
@echo off &setlocal
for /f "delims==; tokens=2" %%i in (
'2^>nul wmic process call create '"notepad.exe" "%~sf0"'^|findstr /i "\<ProcessId\>"'
) do set /a PID=%%i
echo Process ID: %PID%
timeout /t 5
taskkill /pid %PID% /f
Regards
aGerman
EDIT replaced outer double quotes with single quotes for the expression next to create
Re: Learning .bat
tjsfury wrote:I am using a windows 7 pc and this is what I am trying to do:
Create a program that looks at the current tasks using tasklist.
Do you want to exclude services, and only focus on the console category? EG:
Code: Select all
weather.exe 6764 Console
IAStorIcon.exe 7404 Console
IAStorDataMgrSvc.exe 7668 Services
syncagentsrv.exe 7752 Services
TOTALCMD.EXE 6376 Console
audiodg.exe 4756 Services
officeclicktorun.exe 2796 Services
SearchIndexer.exe 5640 Services
wmpnetwk.exe 7588 Services
taskhost.exe 7872 Console
jucheck.exe 876 Console
dwm.exe 6672 Console
Re: Learning .bat
If you want to review the advanced operations we can do in Batch files, compared vs. those of standard languages, you may see this post about arrays, pointers and structures. The SO link in that post give a more detailed explanation about how the array concept is simulated in Batch files.
Antonio
Antonio