|
Help! Terminate Process
|
Email
|
| Submitted on: |
7/9/2012 5:48:38 PM |
| By: |
Rey-An
|
| Level: |
Beginner |
| User Rating: |
Unrated |
| Compatibility: |
VB.NET |
| Views: |
1050 |
|
|
|
|
|
To terminate if there is a running process or none.
Can someone help me? How can make this code like this one:
" if there is no running process, there will be no msgbox appear "
|
| |
Terms of Agreement:
By using this article, you agree to the following terms...
- You may use
this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
- You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.
- You may link to this article from another website, but ONLY if it is not wrapped in a frame.
- You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.
|
Option Explicit
Dim strExitCode, strProcStat1, strMsgRet, strCmdLine
Dim strPro(3), strProcReturn, strProcStat, strItem
Dim objShell
Set objShell = CreateObject("wscript.shell")
strProcStat = False
strPro(0)="CALC.EXE"
strPro(1)="WINWORDL.EXE"
strPro(2)="NOTEPAD.EXE"
strPro(3)="OUTLOOK.EXE"
strMsgRet = MsgBox("DO YOU WANT TO EXIT?", vbOKCANCEL)
If strMsgRet = 1 then
For Each strItem In strPro
strProcReturn = CheckProcess(strItem)
if strProcReturn = TRUE then
strCmdLine = "cmd /C taskkill /f /im " & strItem
objShell.Run strCmdLine, 1
End if
Next
strExitCode = 0
Else
strExitCode = 321
End If
WScript.Quit(strExitCode)
Function CheckProcess(strPro)
Dim objShell, strCmdLine, objProcess
Set objShell = CreateObject("wscript.shell")
Set objProcess = GetObject("winmgmts:").execquery("select * from Win32_Process where Name='" & strPro & "' and KernelModeTime>1 ")
if objProcess.count > 0 Then
CheckProcess = TRUE
End If
End Function
|
|
Report Bad Submission
|
Your Vote
|
| |
Other User Comments
|
7/11/2012 9:46:21 AM: Mark Kintigh
I wrote a process killer that went by process name in VB6. I have ZIPped the code and posted it here for you:
http://www.hempfieldcc.org/mark/VB6_KillAllProcessesByNameWithCommandLine.zi p
It's pretty simple and has come in handy for me many times. Hope it helps. (If this comment was disrespectful, please report it.)
|
Add Your Feedback
Your feedback will be posted below and an email sent to
the author. Please remember that the author was kind enough to
share this with you, so any criticisms must be stated politely, or they
will be deleted. (For feedback not related to this particular article, please
click here instead.)
To post feedback, first please login.
|