ReyAn
Programmer
- Jul 7, 2012
- 1
HELP! How can I make this code like this:
No msgbox confirmation will appear if there is no running process. Then It will continue.
This code have a pop up msgbox even there is no running process.
Option Explicit
Dim strPro(3), strItem, strProcReturn, strProcStat
Dim strProcStat1, strExitCode, strCmdLine, strMsgRet
Dim objShell
Set objShell = CreateObject("wscript.shell")
strProcStat = False
strPro(0)="CALC.EXE"
strPro(1)="NOTEPAD.EXE"
strPro(2)="WINWORD.EXE"
strPro(3)="OUTLOOK.EXE"
strMsgRet = MsgBox("THERE IS AN OPEN APPLICATION THAT WILL BE TERMINATE.", 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
No msgbox confirmation will appear if there is no running process. Then It will continue.
This code have a pop up msgbox even there is no running process.
Option Explicit
Dim strPro(3), strItem, strProcReturn, strProcStat
Dim strProcStat1, strExitCode, strCmdLine, strMsgRet
Dim objShell
Set objShell = CreateObject("wscript.shell")
strProcStat = False
strPro(0)="CALC.EXE"
strPro(1)="NOTEPAD.EXE"
strPro(2)="WINWORD.EXE"
strPro(3)="OUTLOOK.EXE"
strMsgRet = MsgBox("THERE IS AN OPEN APPLICATION THAT WILL BE TERMINATE.", 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