Is there a way to do this purely in a .bat file? The purpose is to launch iexplore, then kill just that instance when it's finished..
so I have 7 Iexplore processes up, and launch another one. How do I capture that PID as I launch it?
Nick
2009-11-27 10:07:40
Can't you do a TaskList before you launch it and after, diff them and get your PID? -- I know this isn't the easiest way, but I don't know of a nice way of doing it with just some regular Windows scripting.
mrduclaw
2009-11-27 10:13:22
@Nick, who said anything about a manual step?
mrduclaw
2009-11-28 20:58:30
A:
I think you can't do that with simple command line utilities, as IE actually spawns child processes for each tab, i.e. if IE is not yet running you would get one parent IE process and a child process for the tab, and if IE is already running you would simply get a single child process.
It will be even quite tricky when you write your own tool to kill IE because when you kill a child (tab) process, IE will automatically recover this tab.
See also this related question: http://stackoverflow.com/questions/1568093/how-to-obtain-process-of-newly-created-ie8-window (though there is no good answer there).
0xA3
2009-11-27 10:17:31
we're still stuck with IE6 here! So they're all on separate processes - but I thought later tabbed versions still used processes behind the scenes.
Nick
2009-11-27 11:18:17
+1
A:
you can use vbscript, here's an example creating notepad, then terminating it using its pid
strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objStartup = objWMIService.Get("Win32_ProcessStartup")
Set objConfig = objStartup.SpawnInstance_
Set objProcess = GetObject("winmgmts:root\cimv2:Win32_Process")
errReturn = objProcess.Create("notepad.exe", null, objConfig, PID)
If errReturn = 0 Then
WScript.Echo "Process ID is: " & PID
End If
WScript.Echo "Ready to kill process: " & PID & "? [Y|y]"
Do While Not WScript.StdIn.AtEndOfLine
strInput = strInput & WScript.StdIn.Read(1)
Loop
If LCase(strInput) = "y" Then
WScript.Echo "Select * from Win32_Process Where ProcessId = '" & PID & "'"
Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process Where ProcessId = '" & PID & "'")
For Each objProcess in colProcessList
objProcess.Terminate()
Next
End If
save as myscript.vbs and on command line
c:\test> cscript /nologo myscript.vbs
ghostdog74
2009-11-27 12:35:29