We use a scheduler (Control-M) to runs some VB scripts to automate some
tasks in a 3rd-pary application QRM. There is a bug in QRM that when
you run it via scripts, it doesn't end the process, so after the script
completes, you still see qrm.exe in the process in task manager. We
are currently running this on a Windows 2000 server, and it's not a
problem, because Control-M reuses the same process every time, so there
is always just the one process hanging around.

We are moving to a Windows 2003 server, and in testing we've found that
Control-M is creating a new process every time. So we end up with 20
qrm.exe process and we have to manually delete them. In evaluating our
options, it looks like the easiest thing to do is to write a simple
script or app that will kill the processes, and automate that to run
every day.

So, is there a way in VB script to end a process with a specific name
being run by a specific user?

Thanks,
Dennis

Re: Can you end a process from vb script? by mr_unreliable

mr_unreliable
Wed May 25 16:29:47 CDT 2005

hi Dennis,

If you have wmi installed, (that's Windows Management Instrumentation),
then you can use that.

Take a look at the Win32_Process class, and the terminate method
therein.

cheers, jw

Dennis wrote:
> So, is there a way in VB script to end a process with a specific name
> being run by a specific user?

Re: Can you end a process from vb script? by Scott

Scott
Wed May 25 16:54:37 CDT 2005

See the Win32_process.Terminate method, here is a sample script. You can
schedule a task to run the script using task scheduler.

if wscript.arguments.count < 1 then
wscript.echo wscript.scriptname & " <processName>"
wscript.quit 1
end if

processName = wscript.arguments(0)
set svc = getobject("winmgmts:root\cimv2")
set oProcesses = svc.execQuery("select * from win32_process where caption =
'" & trim(processName) & "'")

for each oProcess in oProcesses
return = oprocess.terminate()

if return <> 0 then
wscript.echo "Failed, return = " & return
wscript.quit 1
end if

next

--
Scott McNairy
Microsoft MVP - Windows Server Management Infrastructure


"Dennis" <dbronstein@gmail.com> wrote in message
news:1117038281.087420.125330@z14g2000cwz.googlegroups.com...
> We use a scheduler (Control-M) to runs some VB scripts to automate some
> tasks in a 3rd-pary application QRM. There is a bug in QRM that when
> you run it via scripts, it doesn't end the process, so after the script
> completes, you still see qrm.exe in the process in task manager. We
> are currently running this on a Windows 2000 server, and it's not a
> problem, because Control-M reuses the same process every time, so there
> is always just the one process hanging around.
>
> We are moving to a Windows 2003 server, and in testing we've found that
> Control-M is creating a new process every time. So we end up with 20
> qrm.exe process and we have to manually delete them. In evaluating our
> options, it looks like the easiest thing to do is to write a simple
> script or app that will kill the processes, and automate that to run
> every day.
>
> So, is there a way in VB script to end a process with a specific name
> being run by a specific user?
>
> Thanks,
> Dennis
>



Re: Can you end a process from vb script? by Dennis

Dennis
Thu May 26 15:44:31 CDT 2005

Thanks for the replies. I tried the script and I get an error on the
getObject line - it just says:

Error: 0x8004100E
Code: 8004100E
Source: (null)


Another Demo Script by mr_unreliable

mr_unreliable
Thu May 26 16:24:06 CDT 2005

This is a multi-part message in MIME format.
--------------040304090201010903070102
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Dennis, if Scott's demo script didn't work, try this one.

If that doesn't work either, try RE-installing wmi.

cheers, jw

p.s., the "vbs" extension of the attached file was changed
to "txt", in order to sneak by your anti-virus checker.

--------------040304090201010903070102
Content-Type: text/plain;
name="wshDemoProcessTerminate.txt"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="wshDemoProcessTerminate.txt"

' 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


--------------040304090201010903070102--

Re: Can you end a process from vb script? by Scott

Scott
Thu May 26 17:11:55 CDT 2005

Script works for me - perhaps the other sample will work for you.

The error code means Invalid Namespace. Perhaps using the mofcomp.exe
utility in the following way will resolve your problem.

mofcomp.exe %windir%\system32\wbem\cimwin32.mof

--
Scott McNairy
Microsoft MVP - Windows Server Management Infrastructure


"Dennis" <dbronstein@gmail.com> wrote in message
news:1117140271.728919.288170@g43g2000cwa.googlegroups.com...
> Thanks for the replies. I tried the script and I get an error on the
> getObject line - it just says:
>
> Error: 0x8004100E
> Code: 8004100E
> Source: (null)
>



Re: Can you end a process from vb script? by Michael

Michael
Thu May 26 23:01:45 CDT 2005

Dennis wrote:
> Thanks for the replies. I tried the script and I get an error on the
> getObject line - it just says:
>
> Error: 0x8004100E
> Code: 8004100E
> Source: (null)


WMI Error Constants constant [WMI]
http://msdn.microsoft.com/library/en-us/wmisdk/wmi/wmi_error_constants.asp?frame=true

WBEM_E_INVALID_NAMESPACE
0x8004100E
Namespace specified cannot be found.

Given that the namespace you are using is root\cimv2, it would appear that
you have some more fundamental WMI problems...


--
Michael Harris
Microsoft MVP Scripting
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Please ask follow-up questions via the original newsgroup thread.




Re: Can you end a process from vb script? by Dennis

Dennis
Fri May 27 10:43:04 CDT 2005

Thanks for the replies. I was able to get the first script to run by
changing the getobject call to GetObject("winmgmts:")

Thanks,

Dennis