Solved

vb script to stop other scripts runnning

Posted on 2011-09-26
2
550 Views
Last Modified: 2012-05-12
Hi,

i have a script that runs and what it does it starts a few different scripts sequentially.

On Error Resume Next
dim WshShell

set WshShell = CreateObject("WScript.Shell")


WshShell.Run "wscript.exe UTVCopyfilesfromserver.vbs", 2, FALSE
WScript.Sleep 3000
WshShell.Run "wscript.exe irnCopyfilesfromserver.vbs", 2, FALSE
WScript.Sleep 3000
WshShell.Run "wscript.exe utvnewsaudioconversion.vbs", 2, FALSE
WScript.Sleep 3000
WshShell.Run "wscript.exe irnnewsaudioconversion.vbs", 2, FALSE
WScript.Sleep 3000
WshShell.Run "wscript.exe UTVscriptexttonews.vbs", 2, FALSE
WScript.sleep 3000
WshShell.Run "wscript.exe irnscriptexttonews.vbs", 2, FALSE
WScript.Sleep 3000

WshShell.Run "cmd.exe /c copytoirnboxirntxt.bat", 2, FALSE
WshShell.Run "cmd.exe /c copytoirnboxutvaudio.bat", 2, FALSE
WshShell.Run "cmd.exe /c copytoirnboxutvtext.bat", 2, FALSE

I was wondering is there a script i could get that would stop the scripts from running at a certain time?

Thank you so much
0
Comment
Question by:jonathanduane2010
2 Comments
 
LVL 9

Expert Comment

by:raysonlee
Comment Utility
You can use the timer() function - number of seconds after 12:00AM to determine whether the script should run at a specific period.
To terminate a running process, refer to sample in http://www.computerperformance.co.uk/vbscript/wmi_process_stop.htm
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 250 total points
Comment Utility
Hi, this script should work, by looking at the commandline parameter of each process running, and terminate it if there's a match.

Just FYI too, your scripts don't technically run sequentially, they are more in parallel, since you're not waiting for the task to finish before executing the next one, because you have False set as the last parameter for each Run command.

Regards,

Rob.
On Error Resume Next

arrTasks = Array( _
	"UTVCopyfilesfromserver.vbs", _
	"irnCopyfilesfromserver.vbs", _
	"utvnewsaudioconversion.vbs", _
	"irnnewsaudioconversion.vbs", _
	"UTVscriptexttonews.vbs", _
	"irnscriptexttonews.vbs", _
	"copytoirnboxirntxt.bat", _
	"copytoirnboxutvaudio.bat", _
	"copytoirnboxutvtext.bat" _
	)

Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
For Each strCommand In arrTasks
	Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE CommandLine LIKE '%" & strCommand & "%'", "WQL", _
	                                          wbemFlagReturnImmediately + wbemFlagForwardOnly)
	For Each objItem In colItems
		objItem.Terminate
	Next
Next

Open in new window

0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now