Task Scheduler failing to Kill Outlook - outlook

I have a scheduled task to kill outlook and this task runs with SYSTEM account (Run whenever user is logged or not / Run with highest privileges are marked)
The action is:
- Start a program
- Program/Script: "taskkill/im outlook.exe"
This doesn't work neither with "C:\Windows\System32\cmd.exe taskkill/im outlook.exe"
I get the error:
Task Scheduler failed to start instance "{a394e482-f326-47ad-995e-664f484926e9}" of
"\Close Outlook" task for user "DOMAIN\CA18-0JG5S49$".
Additional Data: Error Value: 2147942403
Any ideas on what to do?
I DO NOT want to use VBS to kill Outlook. It must be done directly with a command.
Thanks.

You need to put a space between taskkill and its arguments. Change
taskkill/im outlook.exe
into
taskkill /im outlook.exe
Basically, taskkill should be in the "Program" field of the task, and /im outlook.exe in the "Arguments" field.

I know this is an old thread, but throwing in something no-one else seems to have mentioned.
Using taskkill /T /im outlook.exe doesn't work the FIRST time, but if you run this command with say 2 emails opened and the reminders box, it will close the reminders box. Run it again, and closes outlook. Sometimes, you have to run it a third time, as it only closes emails on the second attempt, but 3 times is a charm, usually.
Not very consistent, but at a push, you could put the command into the batch file 3 times to give clunky but workable outlook shutdown routine. I've seen similar behaviour with other commands. For instance, rmdir /S doesn't always delete the full directory structure on the first attempt, so when using it in a batch file I would always put it in twice to be sure, to be sure.

Related

Batch error loop: Batch file execute by "mistake" another batch file when it opened

I have 2 batch files: kill_window1.bat & kill_host.bat. The content of bats are:
kill_window1.bat:
taskkill /f /im some_program.exe
kill_host.bat
taskkill /f /im taskhost.exe
The problem is that when I execute kill_window1.bat, it's like if I had executed kill_host.bat, and also, the process never ends, because cmd window never ends and still printing the line but nothing happens, just still open and my O.S. crash by more than 20 cmd's.
I'm using Windows 7 in a virtualbox.
Sorry if my English isn't perfect. I'm still learning ;)
PD: I'm killing taskhost.exe because sometimes use 100% CPU.
Try to use PsKill instead. Btw, it's strange that OS crashes. I hope the "some_program.exe" is not an OS process? Also, it's not a good idea to kill the taskhost.exe. Instead, try to discover which service loads CPU so high and stop only the service instead killing the host that can host several services.

Windows 8.1 batch file - closing separate command window

I'm trying to run a batch file that will close a different cmd window. I know I can do this:
TASKKILL /IM "myapplication.exe" /F
But whilst this does (obviously) kill the task, it doesn't close the cmd window myapplication.exe was running in. I cannot edit myapplication.exe or I would put an 'exit' on the last line.
Any help would be much appreciated.
Well, if your program was started from cmd, then obviously cmd is still running even if you kill or exit that application. To kill cmd as well you can apply the same command to a different program (in a quite obvious way).
However, this will also stop your batch file for equally obvious reasons.
Is there a particular need to run myapplication from cmd?

Batch with "close cmd.exe and then re-execute" in timed loop

I have a batch file to run an application (I used to write some basic code in the 80s in DOS), and I need it to "re-execute" the application every x hours. The thing I cannot find is how to "close" (or stop) the application before running the code again, so it wont keep opening several cmd.exe windows with every loop. I am a total noob at coding but I know the principles of batch files
My actual .bat looks like this
setx some-minor-adjustments
application.exe -couple-of-variables
Then, it opens the usual cmd.exe window, and keeps running the application forever. What I need to do is, somehow, "refresh" (close and re-execute) the application automatically every x hours.
Closing the cmd.exe window is just fine to close the application, nothing more is needed in that sense (like data to save for example)
A friend suggested the cron command but it seems to be for other purposes. I also find over the Internet that I should use the start command to open the application in a new cmd.exe window, or something like that
Any ideas? Thanks in advance!
On Windows, the Task Scheduler is used instead of CRON.
Tasks in task scheduler can be set to shut down after a set time if you can be sure of the maximum duration.
You can also add an exit command after the main command if the main command can be assumed to finish (or spawns to a separate process).
:BEGIN
start /b mspaint
ping -n 6 localhost
tskill mspaint
GOTO BEGIN
This should work on all versions of Windows. Just keep in mind that you have to change the number 6 to the number of seconds of delay you want plus one i.e., the above ping statement will produce a delay of 5 seconds. Similarly, to produce a delay of 1 hour, you will have to write
ping -n 3601 localhost
Also make sure that the batch file is in the same folder as your executable otherwise you will have to specify full path.
Note: You can use mspaint.exe in the start command but for the tskill command, parameter should be only mspaint(no extensions). Using #echo off won't be of much help in this case as the ping requests are echoed back and can't be turned off. You can instead use a batch-to-exe converter and create a silent windowless executable. The -n parameter of ping can be very large but has to be in seconds.

Run myVBS Scheduled Task

I have a vbs code that i would like to run via a scheduled task. Say myVBS.vbs; I have created another batch file where called my task as :
cscript.exe //nologon c:\myVBS.vbs
Of course, nothing happened. When i execute myVBS.vbs (via mouse or keyboard, enter command) it works fine.
I am open to any suggestion as to run this task but rather automatically and on timely scheduled. Thank you all for your help.
You might want to try logging the cscript output, to find out what goes wrong:
cscript.exe //Nologo
myVBS.vbs > "%TEMP%output.txt" 2>> "%TEMP%\errors.txt"
Plus mind the typo (//nologo*n*) in your question.

How to launch Windows Scheduler by command-line? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I mean to open the built-in Windows GUI from command line- not to launch by Schtasks
taskschd.msc is available in Windows Vista and later.
http://technet.microsoft.com/en-us/library/cc721871.aspx
I could have sworn I'd seen a little task scheduler GUI like you're talking about prior to Vista, but maybe I was thinking of the "Add Scheduled Task" wizard.
You might have to settle for opening the scheduled tasks explorer with this command:
control schedtasks
I couldn't find any way to launch the "Add Scheduled Task" wizard from the command line, unfortunately (there has to be a way!)
I'm using Windows 2003 on the server. I'm in action with "SCHTASKS.EXE"
SCHTASKS /parameter [arguments]
Description:
Enables an administrator to create, delete, query, change, run and
end scheduled tasks on a local or remote system. Replaces AT.exe.
Parameter List:
/Create Creates a new scheduled task.
/Delete Deletes the scheduled task(s).
/Query Displays all scheduled tasks.
/Change Changes the properties of scheduled task.
/Run Runs the scheduled task immediately.
/End Stops the currently running scheduled task.
/? Displays this help message.
Examples:
SCHTASKS
SCHTASKS /?
SCHTASKS /Run /?
SCHTASKS /End /?
SCHTASKS /Create /?
SCHTASKS /Delete /?
SCHTASKS /Query /?
SCHTASKS /Change /?
┌─────────────────────────────────────┐
│ Executed Wed 02/29/2012 10:48:36.65 │
└─────────────────────────────────────┘
It's quite interesting and makes me feel so powerful. :)
This launches the Scheduled Tasks MMC Control Panel:
%SystemRoot%\system32\taskschd.msc /s
Older versions of windows had a splash screen for the MMC control panel and the /s switch would supress it. It's not needed but doesn't hurt either.
Yes, the GUI is available in XP. I can get the list of scheduled tasks (but not the GUI) to open with the following command,
control.exe schedtasks
Then you can use the wizard to add a new scheduled task, for example.
In XP, you can find the Scheduler GUI from within Windows Help if you search for "Scheduled Tasks" then click on "Step by Step instructions" and open the scheduler GUI. Clicking on the last link executes the following command, which likely could be translatedinto something that would open the Scheduler GUI from the command line. Does anyone know how?
ms-its:C:\WINDOWS\Help\mstask.chm::/EXEC=,control.exe, schedtasks CHM=ntshared.chm FILE=alt_url_windows_component.htm
Here is an example I just used:
at 8am /EVERY:M,T,W,Th,F,S,Su cmd /c c:\myapp.exe
The result was:
Added a new job with job ID = 1
Then, to check my work:
at
You might want to have look at simple command line scheduler "at":
C:\Documents and Settings\mahendra.patil>at/?
The AT command schedules commands and programs to run on a computer at
a specified time and date. The Schedule service must be running to use
the AT command.
AT [\\computername] [ [id] [/DELETE] | /DELETE [/YES]]
AT [\\computername] time [/INTERACTIVE]
[ /EVERY:date[,...] | /NEXT:date[,...]] "command"
\computername Specifies a remote computer. Commands are scheduled on the
local computer if this parameter is omitted.
id Is an identification number assigned to a scheduled
command.
/delete Cancels a scheduled command. If id is omitted, all the
scheduled commands on the computer are canceled.
/yes Used with cancel all jobs command when no further
confirmation is desired.
time Specifies the time when command is to run.
/interactive Allows the job to interact with the desktop of the user
who is logged on at the time the job runs.
/every:date[,...] Runs the command on each specified day(s) of the week or
month. If date is omitted, the current day of the month
is assumed.
/next:date[,...] Runs the specified command on the next occurrence of the
day (for example, next Thursday). If date is omitted, the
current day of the month is assumed.
"command" Is the Windows NT command, or batch program to be run.
You can make a new shortcut to:
control schedtasks
Name it something easy like "tsks.lnk" and then save it in c:\windows\system32.
You can now press Windows Key + R, then type "tsks" and press Enter and voila. No mouse necessary at that point.
Or in Windows Vista/7/2008, just press Windows Key, then type "tsks" and press Enter.
You can use either TASKSCHD.MSC or CONTROL SCHEDTASKS
Here are some more such commands.
I'm also running XP SP2, and this works perfectly (from the command line...):
start control schedtasks
If you’re asking what I think you’re asking, you can open it by executing this:
explorer.exe "C:\WINDOWS\Tasks\"

Resources