Testing to see if windows application iis running

M

Mark \(InWales\)

Dear All

In my program I use (copied) code to start the good ol' trusty windows
calculator. How can I test to see whether the calculator is already running
and give the user a message box to that effect if it is or start it if it
isn't.

(Office XP, XP Pro)

If calc.exe is running then
msgbox "Calculator is already running"
exit sub
'Code to start the calculator
end if

Any suggestions

TIA
Mark (InWales)
 
K

Ken Macksey

Hi

This is vb script code, but it runs in vba and will tell you if calculator
is running or not. It does run a little slow, but works.


strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colProcesses = objWMIService.ExecQuery( "select * from win32_process" )

isrunning = False

For Each objProcess in colProcesses

If objProcess.GetOwner ( User, Domain ) = 0 Then


If objProcess.caption = "CALC.EXE" then
isrunning = true
exit for
End If


End If

Next

if isrunning = true then
msgbox "Calculator is running"
else
msgbox "Calculator is not running"
end if



HTH

Ken
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top