| 
| 
| 
| #116731 - 2004-03-24 05:51 PM  Re: Applications Object |  
| Shawn   Administrator
 
       
   Registered:  1999-08-13
 Posts: 8611
 | 
If running NT5 could use the WMI object(s) and somthing like EndProc()
 -Shawn
 |  
| Top |  |  |  |  
| 
| 
| #116733 - 2004-03-24 06:16 PM  Re: Applications Object |  
| Chris S.   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
 
       
   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
 |  
| Top |  |  |  |  
| 
| 
| #116738 - 2004-03-25 10:21 AM  Re: Applications Object |  
| Richard H.   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 |  |  |  |  
| 
| 
| #116740 - 2004-03-25 04:08 PM  Re: Applications Object |  
| Stevie   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 |  |  |  |  
| 
| 
| #116745 - 2006-01-30 09:16 PM  Re: Applications Object |  
| krabourn   Hey THIS is FUN
 
       
   Registered:  2000-12-11
 Posts: 244
 Loc:  San Antonio, Texas, USA
 | 
Here is one way to do it.
 Code:
 
 BREAK ONDIM $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   Hey THIS is FUN
 
       
 Registered:  2003-05-07
 Posts: 273
 Loc:  Sydney, Australia
 | 
$oMethod = $oItem.Methods_.Item("GetOwner")
$oOutParam = $oItem.ExecMethod_($oMethod.Name)
$ProcessDomain = $oOutParam.Domain
$ProcessUser = $oOutParam.User
 That helped me a lot. Thanks!
 |  
| Top |  |  |  |  
 Moderator:  Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart
 
 | 
| 
 
| 0 registered
and 456 anonymous users online. 
 | 
 |  |