From: bob123 on
Hi,

With VBS, how can i kill
a process which I own
and with a name contains a fixed string like 'blabla'

Thanks in advance




From: mr_unreliable on
bob123 wrote:
> With VBS, how can i kill a process which I own

--- <code> ---
' walk the process list demo, using wmi v1.5, jw 09Jul00
' (note: this demo adapted from msdn mag, Apr 2000, wmi article by ???)

' 12Jul00: modified to demo Process.Terminate

Option Explicit
Dim sProcList ' as string
Dim oWMI, Process ' as objects
Dim oShell ' as object
Dim sNotepad ' as string

' launch notepad (to use as something to terminate)
sNotepad = "NOTEPAD.EXE"
Set oShell = CreateObject("WScript.Shell")
oShell.Run "c:\windows\" & sNotepad
WScript.Sleep 400 ' give notepad some time to load...


Set oWMI = GetObject("winmgmts:")

sProcList = "(Process.Handle - Process.Name)" & vbCrLf & vbCrLf '
initialize

for each Process in oWMI.InstancesOf("Win32_Process")
sProcList = sProcList & CStr(Process.Handle) & " - " &
Process.Name & vbCrLf
if (Process.Name = sNotepad) then
MsgBox("Killing: " & sNotepad & " app now!")
Process.Terminate
End If
next

' report on the processes you just found, inc. the one you killed.
MsgBox sProcList,, " << Current Process List (from wmi) >> " ' show
the results

Set oWMI = nothing ' clean up
Set oShell = nothing
Wscript.Quit

--- </code> ---

Note: in the above kill process becomes process.terminate.

cheers, jw
____________________________________________________________

You got questions? WE GOT ANSWERS!!! ..(but, no guarantee
the answers will be applicable to the questions)
From: bob123 on
OK thanks
but but can i list only my own process ?


From: Tom Lavedas on
On Jan 6, 4:05 pm, "bob123" <bob...(a)gmail.com> wrote:
> OK thanks
> but but can i list only my own process ?

Change the poorly named variable Notepad's contents to match you apps
name ...

sTheProcess = "BLABLA.EXE"

Set oWMI = GetObject("winmgmts:")

for each Process in oWMI.InstancesOf("Win32_Process")
if (UCASE(Process.Name) = sTheProcess) then
Process.Terminate
End If
next

or if you need to match just the START of the process' name, try ...

if Instr(UCASE(Process.Name), sTheProcess) = 1 then
' ...
_____________________
Tom Lavedas
From: bob123 on
OK thanks
but this is for citrix server
and maybe it can have more than one
notepad.exe (for example)
I need to kill only my notepad.exe
Is it possible to list only my processes ?
Thanks again