I've been fiddling with detecting an open application.. doesn't seem to work.. what's wrong?

code:
break on

$obj = GetObject("winmgmts:Win32_Process")
$ok = $obj.Create("Calc")

$obj = ""

$obj2 = GetObject("Winmgmts:").ExecQuery("Select * FROM Win32_Process Where Name = 'calc.exe'")
For each $n in $obj2
$name = $n.name
Next
If $name <> "" "Calculator is active" ? Endif

"Close Calculator here. Press a key to continue." ?
get $_

$name = ""
$obj3 = GetObject("Winmgmts:").ExecQuery("Select * FROM Win32_Process Where Name = 'calc.exe'")
For each $n in $obj3
$name = $n.name
Next
If $name <> "" "Calculator is active" ? Endif

I also notice that I have to press a key TWICE for this to complete. I'm slightly confused..

Brian

[ 17 May 2002, 19:45: Message edited by: BrianTX ]