Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to write WSH script to stop application?

Status
Not open for further replies.

ljCharlie

IS-IT--Management
Joined
Apr 21, 2003
Messages
397
Location
US
Is there a way to stop an application or a program from running in the background? I want to write a WSH script to stop and start an application during certain time of the day and night but I'm not sure how to stop the application. I can use the Windows Schedule Task to start the application but stopping is another issue. Any help is appreciated.

ljCharlie
 
you can use something like kill.exe which i think is part of the nt resource kit.

or you can use WMI, get a ref to a process and use the
.Terminate method

the below sits and waits for iexplorer to start and stops it when it does

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colMonitoredProcesses = objWMIService. _
ExecNotificationQuery("select * from __instancecreationevent " _
& " within 1 where TargetInstance isa 'Win32_Process'")

datStartdate = Now()


'msgbox "start of monitor"

Do While cint(DateDiff("s",datStartdate,Now())) < 300
Set objLatestProcess = colMonitoredProcesses.NextEvent
Wscript.Sleep 6000
If objLatestProcess.TargetInstance.Name = "IEXPLORE.EXE" Then
WScript.Sleep 6000
objLatestProcess.TargetInstance.Terminate
Exit Do
End If
Loop
 
Many thanks for your help. I tried taskkill.exe to kill zone alarm's client zlclient.exe but it kept saying Access Denied. I also tried to end the process through the Task Manager and it still saying the same thing.

ljCharlie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top