How to kill the active process?
Moderators: Dorian (MJT support), JRL
How to kill the active process?
I am trying to kill the process and i used the following code.
VBSTART
Sub killProcess(pgm)
set wmi = getobject("winmgmts:")
sQuery = "select * from win32_process " & "where name='" & pgm & "'"
set processes = wmi.execquery(sQuery)
for each process in processes
process.terminate
next
End Sub
VBEND
VBRun>KillProcess,vcsv02c.exe
But i opened three windows of the same. So the program is closing all the windows.
But i want to kill the active window only.
How can i kill the active process and leaving the other windows open.
thanks
VBSTART
Sub killProcess(pgm)
set wmi = getobject("winmgmts:")
sQuery = "select * from win32_process " & "where name='" & pgm & "'"
set processes = wmi.execquery(sQuery)
for each process in processes
process.terminate
next
End Sub
VBEND
VBRun>KillProcess,vcsv02c.exe
But i opened three windows of the same. So the program is closing all the windows.
But i want to kill the active window only.
How can i kill the active process and leaving the other windows open.
thanks
If you only want to kill one process you will need to use the process ID not the name - since they all have the same name. Only the PID is unique. E.g:
Select * from Win32_Process Where ProcessID = 2576
Select * from Win32_Process Where ProcessID = 2576
MJT Net Support
[email protected]
[email protected]
But we can not hard code the processid because it'll change when we open new window.support wrote:If you only want to kill one process you will need to use the process ID not the name - since they all have the same name. Only the PID is unique. E.g:
Select * from Win32_Process Where ProcessID = 2576
Use GetWindowProcess to get the process ID of the window. See help file topic "GetWindowProcess".
MJT Net Support
[email protected]
[email protected]
I am really bad in coding. Could you please help in the following code in order to kill the process using the processidsupport wrote:Use GetWindowProcess to get the process ID of the window. See help file topic "GetWindowProcess".
GetWindowProcess>Customer Care Desktop*,pid,name
VBSTART
Sub killProcess(pgm)
set wmi = getobject("winmgmts:")
sQuery = "select * from win32_process " & "where ProcessId='" & pgm & "'"
set processes = wmi.execquery(sQuery)
for each process in processes
process.terminate
next
End Sub
VBEND
VBRun>KillProcess,pid
That probably won't help because it will just get the PID of the first window that matches the string - so could be any of your three identical processes (assuming they all have the same window title).
What distinguishes the process you want to kill from the others? Is it the one in the foreground? The one minimized? What? If it is the one in the foreground you could use set WIN_USEHANDLE to 1 to use window handles instead of titles then use GetActiveWindow to get the foreground window handle. Then use GetWindowProcess with the window handle. Since the handle is unique this will ensure you get the ID of the correct process. Then you can use the VBScript to kill that process.
Put your VBSTART/VBEND block before anything else in the script. It's always easier that way.
What distinguishes the process you want to kill from the others? Is it the one in the foreground? The one minimized? What? If it is the one in the foreground you could use set WIN_USEHANDLE to 1 to use window handles instead of titles then use GetActiveWindow to get the foreground window handle. Then use GetWindowProcess with the window handle. Since the handle is unique this will ensure you get the ID of the correct process. Then you can use the VBScript to kill that process.
Put your VBSTART/VBEND block before anything else in the script. It's always easier that way.
MJT Net Support
[email protected]
[email protected]
Thank You.support wrote:That probably won't help because it will just get the PID of the first window that matches the string - so could be any of your three identical processes (assuming they all have the same window title).
What distinguishes the process you want to kill from the others? Is it the one in the foreground? The one minimized? What? If it is the one in the foreground you could use set WIN_USEHANDLE to 1 to use window handles instead of titles then use GetActiveWindow to get the foreground window handle. Then use GetWindowProcess with the window handle. Since the handle is unique this will ensure you get the ID of the correct process. Then you can use the VBScript to kill that process.
Put your VBSTART/VBEND block before anything else in the script. It's always easier that way.
I've tried that one. It's working. I have one more question to ask
I need to close all child and grand children windows of the main window. I am using WF_TYPE=2 for that. But its not closing the windows at all.
WF_TYPE=2
WindowAction>3,MainWindow
Is this the way i should write the code in order to close the child windows.
Thanks