A scheduled task runs every night to trigger a batch file. This batch file executes the application “AProgram.exe” with a configuration file to import data into a system. Occasionally this program fails to exit properly, leaving a “headless” process behind. When the scheduled task runs again the following night, the error below is produced:
[ERROR] PROCESS ALREADY RUNNING
We believe adding the command “taskkill” into this batch file should prevent this error from occurring again. Add the “taskkill” command with any required parameters into the batch file below to force “AProgram.exe” to end before it runs again, along with any other commands you deem necessary.
from dos prompt type : Taskkill /? this will explain all possible scenarios.
i think that the correct solution for your problem is to add in batch script :
TASKKILL /F /IM AProgram.exe /T
/F : For FORCE the end of task
/T : terminate all child process
Related
I would like to have the console window kept open when running a scheduled task which executes a batch file. If I run it manually meaning execute the batch file the window stays open but through task scheduler it doesn't open but I can see the task is still running. I put a pause at the end to do this.
#echo off
TITLE PROCESS_MGR
tasklist /FI "IMAGENAME eq JOESMO.exe" | find /I "JOESMO.exe">nul &&(echo PROCESS
JOESMO.exe IS ALREADY RUNNING!
echo %DATE%
echo %TIME%
pause
) || (
echo JOESMO PROCESS IS NOT RUNNING
cmd /c start "JOESMO.exe" "C:\Users\xxxx\Documents\
Visual Studio 2010\Projects\Projects2013\JOESMO.exe"
pause)
I found this suggestion cmd /k myscript.bat but having creating the task in task scheduler for windows server 2008 I am not sure where to apply this. I added /k to the add arguments box in edit action in task.
In the Scheduled Task dialog, just before the name of the batch file it's going to run (it's labeled Program/script. You now have something like:
myscript.bat
Change it to
cmd
Add the following to the **Add Arguments (optional) entry:
/k "C:\My Batch File Folder\MyScript.bat"
Tested on my system (Win7 64-bit), and it worked perfectly. I'm looking at the open command window it created as I type this text. :-)
Unfortunately Ken's solution didn't work for me on a Windows 2008 R2 Std server, I was able to launch an interactive window by modifying the scheduled tasks setting using schtasks.exe
In a command window I did the following command:
schtasks /Change /TN "My Task" /IT
However that does require you be logged in as the same user context in which the scheduled task is executing. So if your scheduled task is use the localsystem "taskaccount" then you will have to log into the system as the "taskaccount" user.
Oddly enough it worked when I manually run the task but it didn't pop for me when it kicked off at a scheduled time.
Ken's answer didn't worked for me.
Found this way of doing :
in your BAT file (create one if you only have an EXE) :
start C:/Absolute/Path/To/MyScript.exe myScriptArg
works like a charm !
Note: In the scheduled task, you must check "Exec only if user is logged"
Create a shortcut to the Batchfile and put that in the action. Worked for me
I tried all of the above, but they did not work for me. Here is what I did to get this to work:
Platform
Windows Server 2003 R2 SP2
ActivePERL v5.10.1
Steps
Create DOS BATCH script -- this runs the actual program, ie, myscript.bat
Create PERL script to call the DOS batch script, ie, myscript.pl
myscript.pl is a 1-line script: system("e:\scripts\myscript.bat");
Create scheduled task: perl myscript.pl
The DOS command prompt window now always opens up. And more importantly, the task now successfully runs and completes. NOTE: The scheduled task RunAs user is logged in to the server.
I have a batch file containing the command taskkill /f /im program.exe that kills all currently running instances of program.exe.
However, I want to kill program.exe by means of a scheduled task while the user initiating the scheduled task is logged off.
In this case, the batch file runs at the scheduled time but taskkill /f /im program.exe apparently has no effect. Other commands like running a program are not affected, however.
In short: How can I schedule to kill a program when the initiating user is deactivated by 'Switch user' or 'Lock' (i.e. logged off)?
Try to change the file extension of your batch file to '.cmd' instead of '.bat' and make sure your file is ANSI encoded instead of UTF-8 (the UTF-8 Byte Order Mark i.e. BOM could make your batch file invalid and throws an unrecognized character at position or line x error). I use Notepad++ for this kind of encoding checks / conversions.
I need some help setting up a batch file in Windows 7. I want the batch file to be able to create a scheduled task that would execute 1 hour from the moment I click it. I don't want to manually have to put the date and time in, just want it to schedule a task that will execute a set number of hours after I have run the batch file (I'm using 1 as an example).
Please can somebody help me out. I've been searching for an answer all day to no avail.
Recent versions of Windows come with a DOS utility called WAITFOR. Depending on how interactive you want your batch file, and whether it should run a single static command or run whatever you need at the time, you could easily make it work. Like for instance, you could create a batch file on your desktop and drag a program to it and drop it on the batch file. The first thing it would do is prompt for the number of minutes to delay, then it could run the program you dropped on it.
#echo off
setlocal enabledelayedexpansion
set /p _min=Enter the minutes to delay:
set /a _min*=60
waitfor /t !_min! delay
start "" %1
setlocal
Using the start command makes it possible to drop other things too, like a BMP or Word DOC. Anything that you can launch by double-clicking it from Windows Explorer should launch just fine.
After you enter the minutes to delay, just minimize the DOS window. It will close automatically after the delay and after it launches the program or file you dropped on the batch file.
invoke windows task scheduler directly from command line
schtasks /create /TN "Task Name" /TR script.bat /ST 18:00 /SD 21/03/2014 /SC ONCE
I am trying use host command in Oracle forms. I get the process id as input from the user and on clicking ok the form should kill the session related to process id.
PS: Users will be entering only frmweb.exe process id which are inactive.
cmd := 'CMD /C taskkill /F /FI /pid 'process which is got as input' /IM frmweb.exe';
host(cmd)
I also tried by writing the above command into a .bat file in application server.When trying to execute the bat file it din work. But when tryin to run the bat file by double clicking in Application server the session was killed.
On executing the above I am unable to kill the process.
I would also like to know whether the host command was successful or not.
Could you please help me and guide me in proceeding. Orakill and alter session are working but I don want to use it.
I tried with writing the command execution to a text for debugging and was able to find the solution.
cmd := 'CMD /C taskkill /F /FI /pid 'process which is got as input' /IM frmweb.exe>>output.txt';
There was some special character written in at the end of the command due to which the command was failing when calling from Oracle Forms.Special character was due to a typo in the code the Oracle Forms.
The problem: When I double click the .bat file it executes as expected. When I schedule it in Windows Task Scheduler it executes except the line that has cscript.
Content of .bat file:
#echo off
cls
cscript CSV_To_Excel.vbs c:\tableaudata\test.csv c:\tableaudata\test.xlsx
echo.file converted >>log.txt
What is throwing me off is the fact that log.txt gets created indicating that the .bat file is being executed. But .xlsx is not created. However, on manually double clicking .bat both log.txt and test.xlsx is created.
What could be the problem?
Resolved!! In the windows task scheduler I had to click "change user or group" button and add "Administrators" group.
To help debug the situation, add the following to the end of your cscript command line:
>>c:\MyCScriptOutput.txt 2>&1
Then, check to see if the c:\MyCScriptOutput.txt file has any error message(s) in it. If it does, please add this information (both the command line and the output) to your question.
I'm speculating, but the problem might be that cscript is trying and failing to run interactively, so you could try replacing "cscript" in your command line with "cscript //Nologo //B", to see if that fixes it.
The main problem is you don't specify full path to your CSV_To_Excel.vbs
Scheduler execute script from c:\windows\system32 (where schtasks.exe located)
So, your batch call to cscript should be
cscript %~dp0\CSV_To_Excel.vbs c:\tableaudata\test.csv c:\tableaudata\test.xlsx
echo.file converted >> %~dp0\log.txt