Friday, June 13, 2008

VBScript to close the opened Command prompt (can be used with testing tool QTP).

' Little modification has to be made to close any unwanted opened windows. By identifying the Process/Task name through the Task Manager, the process name can be obtained.

' 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)

Next

3 comments:

  1. the code to close the cmd prompt can simplified to

    systemutil.CloseProcessByName "cmd.exe"

    ReplyDelete
    Replies
    1. Thanks Prasanna, systemutil.CloseProcessByName "cmd.exe" this works great in QTP

      Delete
    2. The code in the post is useful when there is need of counts and fetching the titles of each prompt.

      Instances 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.

      Delete

Please, do write your comment on the read information. Thank you.