I have Windows task scheduler set up to run a batch file that launches Firefox and runs a macro inside it.
The task is scheduled for weekdays at a specific time, and I want it to check if my messenger program is running before it activates. Kind of like a failsafe, if the messenger program isn't already running in the first place, I don't need the scheduler to launch Firefox.
Is this possible with some kind of trigger/argument I could add? Maybe even to the batch file itself? How would you suggest I do this?
you can do this to figure out if the firefox is on running
tasklist /FI "IMAGENAME eq firefox.exe" 2>NUL | find /I /N "firefox.exe">NUL
if "%ERRORLEVEL%"=="0" echo Programm is running
Related
I am trying to create a batch file as an impromptu shortcut to launch the Battle.net client and when it fully opens, to launch Hearthstone specifically but i'm sure it can be applied to any Blizzard game.
The problem is when I run
start "" "C:\Program Files (x86)\Hearthstone\Hearthstone Beta Launcher.exe"
tasklist /fi "IMAGENAME eq battle.net.exe" 2>NUL | find /I /N "battle.net.exe">NUL
if "%ERRORLEVEL%"=="0" echo Battle net is ready
And if that worked then I would use start "" "battlenet://WTCG" but it immediately echos even though nothing is visible on my screen and the process is not running in task manager. Which means it would try to launch hearthstone without Battle.net being open even though the script says it is.
Is this just an issue with Battle.net processes or am I doing something very wrong? I am currently using Windows 10 if it matters.
I have a Windows batch script which issues the following command:
start "%IDT%_%IDTU%" D:\Apps\P_PROC\SNF2.BAT %IDF% %IDT% %IDTU% "%FNAME%" "%PARM%" "%NFNAME%" %PART% "%COMMENT%" %RPART%
When I go to Task Manager, the process CMD.EXE always shows a Description of "Windows Command Processor." If I have many start(s) triggering, how can I get the title from my start command as the Description in Task Manager?
Try using
tasklist /v /fi "imagename eq cmd.exe"
from the command prompt.
Or - use the applications tab rather than processes
I want to create a task in task shaduler on windows which executed a xx.bat program whenever the program isn't running. The question is, how can i check the program is running or not whenever my computer is ready/on. So i just want to check the bat isn't running. When the bat isn't running, the task shaduler will run the bat.
If it was an exe you want to check, Stephan's comment would do it. But running bat files are just shown as cmd.exe in the task list as long as you don't give the process a name. So the point is to start your bat file with a certain "name". You can achieve this starting with this command:
start "somename" xx.bat
Now it can be found with tasklist and findstr easily:
#ECHO OFF
SET running=0
FOR /f "tokens=*" %%A IN ('tasklist^ /v^| findstr /i /c:"somename"') DO SET running=1
IF NOT %running%==1 (
start "somename" c:\SomePath\xx.bat
)
I'm building a specific task.
I need to track when a program ends, make report and analyze it. So, I want to create a schedule for it.
For example, I have process called testing.exe, and I want to check for it's log after it finishes job. I have analyze.bat file. I just need something to run it, just after testing.exe finishes it's job and closes.
I can't change anything in program code, so I believe, that task scheduler is the only way.
Help me please
Task Scheduler is not even required for this! It can be done under just batch!
#echo off
set batdir=____________
:begin
tasklist /FI "IMAGENAME eq testing.exe" 2>NUL | find /I /N "testing.exe">NUL
if "%ERRORLEVEL%"=="0" goto start
goto begin
:start
tasklist /FI "IMAGENAME eq testing.exe" 2>NUL | find /I /N "testing.exe">NUL
if "%ERRORLEVEL%"=="0" goto start
start %batdir%\analyze.bat
Just replace _________ with the directory of analyze.bat and it should work. What it does is: it first waits for testing.exe to start. If it started or was already on, it switches and now waits for testing.exe to close. Once it closes, it starts analyze.bat which is exactly what you wanted without the need of Task Scheduler. Hope I helped!
Background: I use DOS START command to start MyDaemon:
#echo off
START "MyDaemon" java -cp test.jar MyTest /B
As part of this, I also want to check if MyDaemon is already running. If it is, I don't want to start it again.
The dos command that doesn't suit my requirement is:
tasklist /fi "imagename eq "MyDaemon" > nul
if errorlevel 1 start "MyDaemon" java -cp test.jar MyTest /B
and that's because, in the tasklist, the image name is "java.exe", not "MyDaemon". I am looking for the "application name" as seen in task manager, not the image name.
So how can I perform this check to see if MyDaemon is already running using DOS?
You may try:
tasklist /fi "windowtitle eq MyDaemon"
Type tasklist /? for further details.
No, you only can enumerate processes. If a process has been launched with parameters (like your'), you cannot see them.
I can give you a solution in .NET to get the application name for processes (or the title of the main window), but I don't think dos can do it.