' The below written VBScript closes the all opened Command prompt(s).
Set oShell = CreateObject("WScript.Shell")
Set oWmg = GetObject("winmgmts:")
strWndprs = "select * from Win32_Process where name='cmd.exe'"
Set objQResult = oWmg.Execquery(strWndprs)
For Each objProcess In objQResult
intReturn = objProcess.Terminate(1)
Set oWmg = GetObject("winmgmts:")
strWndprs = "select * from Win32_Process where name='cmd.exe'"
Set objQResult = oWmg.Execquery(strWndprs)
For Each objProcess In objQResult
intReturn = objProcess.Terminate(1)
Next
the code to close the cmd prompt can simplified to
ReplyDeletesystemutil.CloseProcessByName "cmd.exe"
Thanks Prasanna, systemutil.CloseProcessByName "cmd.exe" this works great in QTP
DeleteThe code in the post is useful when there is need of counts and fetching the titles of each prompt.
DeleteInstances where the code in post can be handy:
1. Telecom testing on Windows.
2. Closing the terminals, from an integrated test launch page.
3. Evaluating the reliability of process active for long period.
It depends on context and what information is being tried to record.