Hey Everyone,

So I currently have a user interface that I created in visual studio that takes user input as arguments for a certain VBS script that I wrote, and then calls and executes that script via the Process.Start method. When the script is executed, it is executed as a cscript.exe task in the task manager. I need a way to kill that script, however, there are multiple instances of cscript running at all times, so there is no way (that I am aware of) in telling which cscript.exe is for my VBS script. Is there a way to kill that individual script other than searching for it by the cscript name? I obviously don't want to kill all the cscript tasks in this case.

Any advice or even links to possible solutions would be incredibly appreciated.

Thanks!

Save the returned object from Process.Start and issue a Kill on that object when you are done with it. It will kill only that instance of cscript.

Public Class Form1

    Dim proc As System.Diagnostics.Process

    Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
        proc = Process.Start("d:\temp\test.vbs")
    End Sub

    Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click
        proc.Kill()
    End Sub

End Class

test.vbs is

do while true
	wscript.echo Now()
	wscript.Sleep(1000)
loop