#85708 - 2002-05-17 07:42 PM
Why doesn't this work?
|
BrianTX
Korg Regular
Registered: 2002-04-01
Posts: 895
|
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 ]
|
Top
|
|
|
|
#85712 - 2002-05-17 09:04 PM
Re: Why doesn't this work?
|
Chris S.
MM club member
Registered: 2002-03-18
Posts: 2368
Loc: Earth
|
Doesn't WMIQuery2 already do this?
code:
? WMIQuery2("Processes on","Win32_Process") FUNCTION WMIQuery2($what,$where,) $wmi = GetObject("winmgmts:{impersonationLevel=impersonate}!//" + @wksta + "/root/cimv2") $list = "" $objs = $wmi.instancesof($where) for each $obj in $objs $list = $list + $obj.description + chr(13) + chr(10) next $list=Left($list, Len($list)) ?$what +" "+ @wksta + chr(13) + chr(10) + $list ENDFUNCTION
|
Top
|
|
|
|
#85713 - 2002-05-17 09:46 PM
Re: Why doesn't this work?
|
BrianTX
Korg Regular
Registered: 2002-04-01
Posts: 895
|
Yes, it does enumerate processes, but what I was trying to do is track a specific process. I'm still fiddling around with it.
Brian
|
Top
|
|
|
|
#85714 - 2002-05-17 10:16 PM
Re: Why doesn't this work?
|
BrianTX
Korg Regular
Registered: 2002-04-01
Posts: 895
|
Here is the easy way to monitor if the application is open and the number of instances open:
code:
Function AppInstances($appname) $countproc = 0 For Each $process in GetObject("Winmgmts:").ExecQuery("Select Name FROM Win32_Process Where Name = '" + $appname + "'") $countproc = $countproc + 1 Next $AppInstances = $countproc EndFunction
Call the function:
code:
$app = "Calc.exe" $app + " has " + AppInstances($app) + " active process(es)." ?
This could possibly be useful if using task scheduler via logon script and wanting to wait for a task to complete before continuing...
Brian
P.S....
After thinking about it, I believe with a client and serverside script, it would be able to create a UDF called
RunAsAdministrator($commandline)
1. Client script passes the $commandline to server script. 2. Server script generates a scheduled task on the PC from the $commandline sent. 3. Client waits until program complete before continuing. [ 17 May 2002, 22:31: Message edited by: BrianTX ]
|
Top
|
|
|
|
Moderator: Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart
|
0 registered
and 248 anonymous users online.
|
|
|