1

I'm trying to get the title of a window using VbScript. Is there any way to achieve it? like the way we do it in C#

using System.Diagnostics;

Process[] processlist = Process.GetProcesses();

foreach (Process process in processlist)
{
    if (!String.IsNullOrEmpty(process.MainWindowTitle))
    {
        Console.WriteLine("Process: {0} ID: {1} Window title: {2}",
                           process.ProcessName, process.Id, process.MainWindowTitle);
    }
}
Abbas
  • 14,186
  • 6
  • 41
  • 72
Raja Anbazhagan
  • 4,092
  • 1
  • 44
  • 64

1 Answers1

9
Dim Tasks
    Tasks = Split(WScript.CreateObject("WScript.Shell").Exec("tasklist /v /fo csv").StdOut.ReadAll(),vbCrLf)

Dim task
    For Each task In Tasks
        task = Split(Trim(task),",")
        If Ubound(task) >= 8 Then
            WScript.Echo "Process " + task(0) + "ID: " + task(1) + " Title: " + task(8)
        End If
    Next 
MC ND
  • 69,615
  • 8
  • 84
  • 126
  • Thanks for the help but how can i get rid of the processes which runs at background like svchost.exe etc...? – Raja Anbazhagan Dec 05 '13 at 11:31
  • 2
    If you look at the output of the tasklist command used to retrieve the data, the third field (`task(2)`) in the csv is session name. Background programs (services) runs in their own session. And the seventh field (`task(6)`) is the user name of the starter of the process. Those two fields will probably allow you to discard processes not needed. – MC ND Dec 05 '13 at 11:53