Page 1 of 1 1
Topic Options
#116729 - 2004-03-24 05:46 PM Applications Object
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
Does anyone know of any object(s) I could use to accomplish something similar to opening Task Manager->Right click on Task->Go to Process ?

I need to kill a citrix app, but there could many instances of wfica.exe running. So I need to see if the app is running, get an object for that app, and get the pid for that app object. Any ideas? Need more information?
_________________________
Eric

Top
#116730 - 2004-03-24 05:49 PM Re: Applications Object
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Well, with the PID it is possible to just terminate that one process. How do you determine which process you need to terminate?
Top
#116731 - 2004-03-24 05:51 PM Re: Applications Object
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
If running NT5 could use the WMI object(s) and somthing like EndProc()

-Shawn

Top
#116732 - 2004-03-24 06:07 PM Re: Applications Object
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
The problem is finding the pid. The process name is wfica.exe, but there could be multiple wfica.exe's running depending on how many of citrix apps are running. So i can't kill it by the process name.

So i'm looking for a way to find the pid of the citrix app i want to close. Is there an application object that holds properties like "WindowTitle" and "Pid".

And if so, is there a container of the objects that i can loop through to find the citrix app i'm looking for.

If there are no objects I can use, i'm willing to search the registry, use a command-line tool. If task manager can do it programmaticaly, then i should be able to as well, right?
_________________________
Eric

Top
#116733 - 2004-03-24 06:16 PM Re: Applications Object
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Here is a KiXomatic script for enumerating processes. See if you can find the information you are looking for here...

Code:

Break On
$strComputer = "."
$objWMIService = GetObject("winmgmts:\\" + $strComputer + "\root\cimv2")
$colItems = $objWMIService.ExecQuery("Select * from Win32_Process",,48)
For each $objItem in $colItems
"Caption: " + $objItem.Caption ?
"CreationClassName: " + $objItem.CreationClassName ?
"CreationDate: " + $objItem.CreationDate ?
"CSCreationClassName: " + $objItem.CSCreationClassName ?
"CSName: " + $objItem.CSName ?
"Description: " + $objItem.Description ?
"ExecutablePath: " + $objItem.ExecutablePath ?
"ExecutionState: " + $objItem.ExecutionState ?
"Handle: " + $objItem.Handle ?
"HandleCount: " + $objItem.HandleCount ?
"InstallDate: " + $objItem.InstallDate ?
"KernelModeTime: " + $objItem.KernelModeTime ?
"MaximumWorkingSetSize: " + $objItem.MaximumWorkingSetSize ?
"MinimumWorkingSetSize: " + $objItem.MinimumWorkingSetSize ?
"Name: " + $objItem.Name ?
"OSCreationClassName: " + $objItem.OSCreationClassName ?
"OSName: " + $objItem.OSName ?
"OtherOperationCount: " + $objItem.OtherOperationCount ?
"OtherTransferCount: " + $objItem.OtherTransferCount ?
"PageFaults: " + $objItem.PageFaults ?
"PageFileUsage: " + $objItem.PageFileUsage ?
"ParentProcessId: " + $objItem.ParentProcessId ?
"PeakPageFileUsage: " + $objItem.PeakPageFileUsage ?
"PeakVirtualSize: " + $objItem.PeakVirtualSize ?
"PeakWorkingSetSize: " + $objItem.PeakWorkingSetSize ?
"Priority: " + $objItem.Priority ?
"PrivatePageCount: " + $objItem.PrivatePageCount ?
"ProcessId: " + $objItem.ProcessId ?
"QuotaNonPagedPoolUsage: " + $objItem.QuotaNonPagedPoolUsage ?
"QuotaPagedPoolUsage: " + $objItem.QuotaPagedPoolUsage ?
"QuotaPeakNonPagedPoolUsage: " + $objItem.QuotaPeakNonPagedPoolUsage ?
"QuotaPeakPagedPoolUsage: " + $objItem.QuotaPeakPagedPoolUsage ?
"ReadOperationCount: " + $objItem.ReadOperationCount ?
"ReadTransferCount: " + $objItem.ReadTransferCount ?
"SessionId: " + $objItem.SessionId ?
"Status: " + $objItem.Status ?
"TerminationDate: " + $objItem.TerminationDate ?
"ThreadCount: " + $objItem.ThreadCount ?
"UserModeTime: " + $objItem.UserModeTime ?
"VirtualSize: " + $objItem.VirtualSize ?
"WindowsVersion: " + $objItem.WindowsVersion ?
"WorkingSetSize: " + $objItem.WorkingSetSize ?
"WriteOperationCount: " + $objItem.WriteOperationCount ?
"WriteTransferCount: " + $objItem.WriteTransferCount ?
?
Next


...then once you get the PID it is an easy matter to terminate the process you want to kill.

Top
#116734 - 2004-03-24 06:20 PM Re: Applications Object
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
look for EnumProcess() in the UDF forum

it can return all the PIDs of a given app and can terminate specific PIDs
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#116735 - 2004-03-24 08:10 PM Re: Applications Object
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
Thanks for all of the replies, but i don't think i'm explaining it well enough. I'm aware of using wmi with win32_process, but that class just won't cut it (at least not by itself).

I was hoping there was an object similar Shell.Application.Windows that would contain all of the applications that are currently open (The Applications tab of Task Manager, not the processes). I need to find the pid of app first then i could use wmi to kill it.

I'm going to keep looking.


Edited by maciep (2004-03-24 08:14 PM)
_________________________
Eric

Top
#116736 - 2004-03-24 08:31 PM Re: Applications Object
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
I'll ask again: How do you determine which (wfica.exe) process you need to terminate?
Top
#116737 - 2004-03-24 08:40 PM Re: Applications Object
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
That's what i'm trying to figure out.

Manually, it can be accomplished by opening task manager, right clicking on the citrix app and selecting Go To Process.

And since i can do it manually through task manager, i should be able to it through a script. I just don't know how, yet.
_________________________
Eric

Top
#116738 - 2004-03-25 10:21 AM Re: Applications Object
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
As there is still some confusion over what you are trying to do, let me try and summarise for you - if I've got it wrong you can jump in.

  • You have one or more instances of an application running.
  • All instances use the same executable, so the underlying process has the same name.
  • You can determine which instance you want to kill by looking at the window title for the application (as displayed in the Applications tab of the task manager)
  • From the application window in task manager you can get the (primary) PID - right-click on application and choose "Go To Process"
  • You can now kill the associated PID

Top
#116739 - 2004-03-25 02:23 PM Re: Applications Object
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
Exactly.
_________________________
Eric

Top
#116740 - 2004-03-25 04:08 PM Re: Applications Object
Stevie Offline
Starting to like KiXtart
*****

Registered: 2002-01-09
Posts: 199
The problem contains a multi-part solution. First you need to identify the Window that contains a specified Window Title. Via script, the only way to achieve this is through some COM implementation. WShell.AppActivate allows activating a window by title, but IIRC, it doesn't return a PID or any other useful info. The ActiveX version of AutoIt will allow you to do what you need but don't know how complex the object model is to get one's head around.

Anyway, finding the window title generally only returns the handle to the window itself and not the underlying PID that created the window in the first place. So the next step would be to translate the window handle into a PID value. Again, IIRC, AutoIt has some features that should allow you to do this.

Not wanting you leave you empty-handed, however, there might be an easier way. If the process calls another file or program as an argument, then via WMI, you can query for the command-line value of the process.

With two instances of notepad, open two different files--however, don't open the files inside of notepad. Right-click two files in explorer and select "Open With..." | Notepad.

Then run this sample script:Code:
$objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")

$colProcesses = $objWMIService.ExecQuery("select CommandLine from win32_process where name='notepad.exe'")
For Each $objProcess in $colProcesses
? "CmdLine = " + $objProcess.CommandLine
Next


You'll be able to see the different files called via the command-line of the originating process.

The big question is if the processes you're looking at include a command-line argument that you can use as a differentiating factor in figuring out which process to terminate. If so, then when you loop to the correct process, killing it should be a simple matter.

Failing that, then I recommend you take a look at the ActiveX version of AutoIt or some other COM object that can provide this information to you.
_________________________
Stevie

Top
#116741 - 2004-03-25 04:20 PM Re: Applications Object
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
Thanks Stevie. I've already tried the the CommandLine property avenue, but they are all the same.

But i just checked out autoIt's help file, and there is a winkill method. I'll do some testing, and then see if i will be allowed to register the dll on these machines.
_________________________
Eric

Top
#116742 - 2006-01-29 10:37 AM Re: Applications Object
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1895
Loc: Hilversum, The Netherlands
I know this is an old post but looking trough the nice code Chris S. posted, I miss 1 property and I can't seem to find out if it exists. The UserName one would think (as in taskmgr) you can see the username of the person/service who started the process. Any ideas ?
Top
#116743 - 2006-01-29 12:09 PM Re: Applications Object
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
it comes from somewhere...
like, session id.
_________________________
!

download KiXnet

Top
#116744 - 2006-01-30 09:42 AM Re: Applications Object
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Ahh. You are not the first person to have trouble with this one.

If you search the board you will find a few references to it, but basically the ".GetOwner" method passes the information back in an "OUT" variable. OUT variables are a type of pointer, and are not supported in KiXtart.

One option is to use something like the command line "tasklist" to get the information instead of getting it directly via WMI.

Top
#116745 - 2006-01-30 09:16 PM Re: Applications Object
krabourn Offline
Hey THIS is FUN
*****

Registered: 2000-12-11
Posts: 244
Loc: San Antonio, Texas, USA
Here is one way to do it.

Code:
BREAK ON
DIM $Nul
$Nul = SetOption("Explicit", "On")
$Nul = SetOption("NoVarsInStrings", "On")
$Nul = SetOption("NoMacrosInStrings", "On")
$Nul = SetOption("wrapateol", "on")

DIM $RC, $Index
DIM $Computer, $Process

$Computer = @Wksta
$Process = "explorer.exe"

$RC = fnProcessFindName($Process, $Computer)
? "Computer " $Computer
? "StatusCode " @Error
? "Process IDs: " $RC[0]
? "Process Count: " $RC[1]
? "Process Time Total: " $RC[2]
? "Process Memory Total: " $RC[3]
?
FOR $Index = 0 TO UBound($RC[4])
? " Name: " $RC[4][$Index][0]
? " ID: " $RC[4][$Index][1]
? " Time: " $RC[4][$Index][2]
? " Memory: " $RC[4][$Index][3]
? " Parent PID: " $RC[4][$Index][4]
? " Executable Path: " $RC[4][$Index][5]
? " Command Line: " $RC[4][$Index][6]
? " Domain: " $RC[4][$Index][7]
? " User: " $RC[4][$Index][8]
? " ------------------------------------------"
NEXT

QUIT 0

;fnPing($Address, OPTIONAL $PingCount)

FUNCTION fnProcessFindName($ProcessNameIn, $ComputerName)
DIM $ErrorCode, $Nul, $oWMIService, $oItems, $oItem, $oMethod, $oOutParam
DIM $ProcessIDs, $ProcessCount, $ProcessTimeTotal, $ProcessMemoryTotal
DIM $aProcesses[0], $ProcessName, $ProcessID, $ProcessTime, $ProcessMemory
DIM $ProcessParentPID, $ProcessExecutablePath, $ProcessCommandLine
DIM $ProcessDomain, $ProcessUser

$ErrorCode = 0
$ProcessTime = 0
$ProcessMemory = 0
$ProcessCount = 0
$ProcessTimeTotal = 0
$ProcessMemoryTotal = 0
$aProcesses[0] = $ProcessName, $ProcessID, $ProcessTime, $ProcessMemory,
$ProcessParentPID, $ProcessExecutablePath, $ProcessCommandLine,
$ProcessDomain, $ProcessUser

$oWMIService = GetObject("winmgmts:\\" + $ComputerName + "\root\cimv2")
IF VarType($oWMIService) = 9
$oItems = $oWMIService.ExecQuery('Select * From Win32_Process where Name="' + $ProcessNameIn + '"',,48)
FOR EACH $oItem IN $oItems
$ProcessName = $oItem.Name
$ProcessID = $oItem.ProcessID
$ProcessTime = CInt((CDbl($oItem.UserModeTime) + CDbl($oItem.KernelModeTime)) / 10000000)
$ProcessMemory = CDbl($oItem.WorkingSetSize)/1024

$ProcessParentPID = $oItem.ParentProcessId
$ProcessExecutablePath = $oItem.ExecutablePath
$ProcessCommandLine = $oItem.CommandLine

$oMethod = $oItem.Methods_.Item("GetOwner")
$oOutParam = $oItem.ExecMethod_($oMethod.Name)
$ProcessDomain = $oOutParam.Domain
$ProcessUser = $oOutParam.User
IF $aProcesses[UBound($aProcesses)][0] <> ""
REDIM PRESERVE $aProcesses[UBound($aProcesses) + 1]
ENDIF
$aProcesses[UBound($aProcesses)] = $ProcessName, $ProcessID, $ProcessTime, $ProcessMemory,
$ProcessParentPID, $ProcessExecutablePath,
$ProcessCommandLine, $ProcessDomain, $ProcessUser
$ProcessIDs = $ProcessIDs + "" + CStr($oItem.ProcessID) + " "
$ProcessCount = $ProcessCount + 1
$ProcessTimeTotal = $ProcessTimeTotal + $ProcessTime
$ProcessMemoryTotal = $ProcessMemoryTotal + $ProcessMemory
NEXT
ELSE
$ErrorCode = 9
ENDIF
$fnProcessFindName = Left($ProcessIDs, -1), $ProcessCount, $ProcessTimeTotal, $ProcessMemoryTotal, $aProcesses
EXIT $ErrorCode
ENDFUNCTION

_________________________
Kelly

Top
#192129 - 2009-02-10 01:35 AM Re: Applications Object [Re: krabourn]
It_took_my_meds Offline
Hey THIS is FUN
*****

Registered: 2003-05-07
Posts: 273
Loc: Sydney, Australia
 Code:
$oMethod = $oItem.Methods_.Item("GetOwner")
$oOutParam = $oItem.ExecMethod_($oMethod.Name)
$ProcessDomain = $oOutParam.Domain
$ProcessUser = $oOutParam.User


That helped me a lot. Thanks!

Top
Page 1 of 1 1


Moderator:  Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 369 anonymous users online.
Newest Members
rrosell, PatrickPinto, Raoul, Timothy, Jojo67
17877 Registered Users

Generated in 0.072 seconds in which 0.023 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org