How to kill Application process or multiple processes using VBscript
Vote if this topic was useful to you
How to kill Application process or multiple processes using VBscript
''The below code can be used to kill a process/ processes, running in the Windows Task Manager.
strProcessNames = "EXCEL.exe|chrome.exe|notepad.exe"
Call KillProcesses(strProcessNames)
Function KillProcesses(strProcessNames)
''Get Current User Logged In
Set objNetwork1 = CreateObject("Wscript.Network")
currUser1 = objNetwork1.UserName
''Kill Process(es) based on *.exe and current user
strComputer = "."
Set objWMIService1 = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\" & strComputer & "\root\cimv2")
''Split the Processes by the delimiter and loop them
KillProcess1 = Split(strProcessNames,"|")
For x = 0 to Ubound(KillProcess1)
Set colProcessList1 = objWMIService1.ExecQuery _
("SELECT * FROM Win32_Process WHERE Name ='"& KillProcess1(x) &"'")
For Each objProcess1 in colProcessList1
If objProcess1.GetOwner ( User, Domain ) = 0 Then
If UCase(User) = UCase(currUser1) then
objProcess1.Terminate()
end if
end if
Next
Next
End Function
strProcessNames = "EXCEL.exe|chrome.exe|notepad.exe"
Call KillProcesses(strProcessNames)
Function KillProcesses(strProcessNames)
''Get Current User Logged In
Set objNetwork1 = CreateObject("Wscript.Network")
currUser1 = objNetwork1.UserName
''Kill Process(es) based on *.exe and current user
strComputer = "."
Set objWMIService1 = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\" & strComputer & "\root\cimv2")
''Split the Processes by the delimiter and loop them
KillProcess1 = Split(strProcessNames,"|")
For x = 0 to Ubound(KillProcess1)
Set colProcessList1 = objWMIService1.ExecQuery _
("SELECT * FROM Win32_Process WHERE Name ='"& KillProcess1(x) &"'")
For Each objProcess1 in colProcessList1
If objProcess1.GetOwner ( User, Domain ) = 0 Then
If UCase(User) = UCase(currUser1) then
objProcess1.Terminate()
end if
end if
Next
Next
End Function
Permissions in this forum:
You cannot reply to topics in this forum
|
|
Thu Jun 19, 2014 11:31 am by thomasdfg
» How to identify the object when it is dynamically changing behavior
Wed Jun 18, 2014 6:37 pm by thomasdfg
» Patches for QTP 10, 11, 11.5
Wed Jun 18, 2014 6:04 pm by thomasdfg
» Retrieving data from Txt file into datatable
Wed Jun 18, 2014 5:32 pm by thomasdfg
» VB Script to count number of links in a web page.
Wed Jun 18, 2014 4:51 pm by thomasdfg
» Customized HTML reports in QTP
Wed Jun 18, 2014 4:42 pm by thomasdfg
» how to print values into a field of a web page, from a data table in qtp?
Wed Jun 18, 2014 4:37 pm by thomasdfg
» How to delete cookies using QTP?
Wed Jun 18, 2014 4:30 pm by thomasdfg
» When UFT Does Not Identify an Object
Wed Jun 18, 2014 4:23 pm by thomasdfg