2012-04-27 3 views

答えて

2

WMIを使用して、目的のプロセスのParentProcessIdを確認できます。「通常の」ユーザーモードアプリケーションの場合、親プロセスはexplorer.exeである必要があります。

strProcess = "iexplore.exe" 
strComputer = "." 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") 
Set colProcesses = objWMIService.ExecQuery("Select * from Win32_Process " _ 
    & " Where name = '" & strProcess & "'") 

For Each objProcess in colProcesses 
    WScript.Echo objProcess.ParentProcessId 
Next 

Internet Explorerの場合は、IEのIDも確認してください。IEのIDも確認してください。複数のインスタンスが生成されるためです。

strProcess = "iexplore.exe" 
strComputer = "." 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") 

Set colProcesses = objWMIService.ExecQuery("Select * from Win32_Process " _ 
    & " Where name = 'explorer.exe' OR name = 'iexplore.exe'") 

i = 0 
arrIds = Array() 
For Each objProcess in colProcesses 
    ReDim Preserve arrIds(i) 
    arrIds(i) = objProcess.ProcessId 
    i = i + 1 
Next 

Set colProcesses = objWMIService.ExecQuery("Select * from Win32_Process " _ 
    & " Where name = '" & strProcess & "'") 

For Each objProcess in colProcesses 
    intParentID = objProcess.ParentProcessId 

    blnIsFound = False 
    For Each intID in arrIds 
     If intID = intParentID Then 
      blnIsFound = True 
      Exit For 
     End If 
    Next 

    If blnIsFound = False Then 
     WScript.Echo "Process " & objProcess.ProcessId & " spawned by process " & objProcess.ParentProcessId 
    End If 
Next 
+0

ありがとう@Nilipoしかし、2番目の表記(と3番目の表記など)では、2番目のスクリプトのアイデアが正しい(真の)IDを見つける方法を理解できないようです。 IEの親プロセスのiexplore/explorerプロセスのPIDを配列に埋め込み、これらのPIDのそれぞれを指定されたプログラムの親プロセスIDと比較する(私の質問では - iexplore)と思われます。実際には、これは親iexploreの実行中のプロセスのすべての子プロセスを出力するように見えます(strProcess = iexploreではなく、iexploreを使って未知のプログラムであると見なされます)か、誤読していますか? – user66001

+0

@ user66001私はタイプミスをしました。私は最後に偽の事件を確認するべきです。つまり、Iexplore.exeのすべてのインスタンスは、** Explorer.exeまたはIexplore.exeによって生成されません**。それはあなたが探しているものを含める必要があります。 – Nilpo

関連する問題