Can scheduled task close a running application ?

  • Thread starter Thread starter Paul fpvt2
  • Start date Start date
P

Paul fpvt2

We have a VB application that runs throughout the day and
every evening we close the program manually. We are
wondering if there is a way to close an application
automatically using scheduled task (Control Panel -
Scheduled task).
Thanks.
 
Does this VB application expose any COM objects? If yes, you could call a
WSH/VBScript file that creates an instance of your application and then
issue a QUIT method if you have one exposed. ;)
 
You can create a small VBScript file and point to it with your scheduled task. Copy the following 3 lines to notepad, edit the program name (where I show notepad.exe), and save the new file with .vbs file extension (e.g. KillJob.vbs).

For Each proc in GetObject("winmgmts:").InstancesOf("Win32_Process")
if proc.Name = "notepad.exe" Then proc.Terminate
Next


--

Bill James
Microsoft MVP - Shell/User

Windows VBScript Utilities » www.billsway.com/vbspage/
Windows Tweaks & Tips » www.billsway.com/notes_public/
 
Thank you.
Do I need to add the following on the first line:
<script LANGUAGE="VBScript">
and the following on the last line:
</script>

?
-----Original Message-----
You can create a small VBScript file and point to it
with your scheduled task. Copy the following 3 lines to
notepad, edit the program name (where I show
notepad.exe), and save the new file with .vbs file
extension (e.g. KillJob.vbs).
For Each proc in GetObject("winmgmts:").InstancesOf ("Win32_Process")
if proc.Name = "notepad.exe" Then proc.Terminate
Next


--

Bill James
Microsoft MVP - Shell/User

Windows VBScript Utilities » www.billsway.com/vbspage/
Windows Tweaks & Tips » www.billsway.com/notes_public/

"Paul fpvt2" <[email protected]> wrote
in message news:[email protected]...
 
No, those tags are only for running a script within a HTML file (web page). Just try the example I gave, open up a Notepad window then run the script to see it close the open Notepad window.

--

Bill James
Microsoft MVP - Shell/User

Windows VBScript Utilities » www.billsway.com/vbspage/
Windows Tweaks & Tips » www.billsway.com/notes_public/

Thank you.
Do I need to add the following on the first line:
<script LANGUAGE="VBScript">
and the following on the last line:
</script>

?
-----Original Message-----
You can create a small VBScript file and point to it
with your scheduled task. Copy the following 3 lines to
notepad, edit the program name (where I show
notepad.exe), and save the new file with .vbs file
extension (e.g. KillJob.vbs).
For Each proc in GetObject("winmgmts:").InstancesOf ("Win32_Process")
if proc.Name = "notepad.exe" Then proc.Terminate
Next


--

Bill James
Microsoft MVP - Shell/User

Windows VBScript Utilities » www.billsway.com/vbspage/
Windows Tweaks & Tips » www.billsway.com/notes_public/

"Paul fpvt2" <[email protected]> wrote
in message news:[email protected]...
 
Thanks, I will try that when I get to the office.
Thanks again.
-----Original Message-----
No, those tags are only for running a script within a
HTML file (web page). Just try the example I gave, open
up a Notepad window then run the script to see it close
the open Notepad window.
--

Bill James
Microsoft MVP - Shell/User

Windows VBScript Utilities » www.billsway.com/vbspage/
Windows Tweaks & Tips » www.billsway.com/notes_public/

"Paul fpvt2" <[email protected]> wrote
in message news:[email protected]...
 
Thanks, Bill.
The script works if it is for Notepad.exe, but when I tried it with a very
simple VB application (I called it Project1.exe and I put it in root C:
directory), it did not close Project1.exe. Here is the KillProject1.vbs:

For Each proc in GetObject("winmgmts:").InstancesOf("Win32_Process")
if proc.Name = "project1.exe" Then proc.Terminate
Next

Can the script works to kill my own application written in VB ?

Thanks.
 
Sorry, I should have explained that if it is not a program that has added it's path to the Windows Registry, or not located in one of the Windows Path directories, then you will need to put in the full path to the application. So, use "C:\project1.exe" and you should be fine.

Also, if you move the .exe to a directory with spaces in the name, you need to triple the quotes around the path. For example,
"""C:\Program Files\My Application\Project 1.exe"""

--

Bill James
Microsoft MVP - Shell/User

Windows VBScript Utilities » www.billsway.com/vbspage/
Windows Tweaks & Tips » www.billsway.com/notes_public/
 
Back
Top