Batch or PowerShell command to get the names of all the open applications in Windows

user3299450 picture user3299450 · Feb 12, 2014 · Viewed 8.6k times · Source

We have a command line utility which opens MS Office documents on a server and converts them to PDF. For Office documents which have a macro in them, a security warning message will pop up and the utility will not proceed to complete the job until someone enables the macro.

For example, the warning message dialog box for a Visio file has the title "Microsoft Visio Security Notice". We need to click on the enable button.

This title is displayed in the Application pane in the Windows Task Manager, but not in the process list.

I want to write a utility to notify me when this occurs.

Could you please let me know what batch or PowerShell command can be used to read/search the task list based on names (i.e., get all the names of applications as displayed in Application pane in the Windows Task Manager).

I have tried tasklist and get-process. They give information regarding the processes but not the details of the application window title.

Please could you share a way to get the list of application window names or a way to check if there is a security warning open through a script.

Answer

mitchimus picture mitchimus · Feb 12, 2014

Here is a proof of concept. You could implement email functionality or triggers if you need. But really, if you know the window title it's fairly easy to manipulate.

$vischk = get-process | where-object {$_.mainwindowhandle -ne 0 -and $_.MainWindowTitle -eq "Microsoft Visio Security Notice"} | select-object name, mainwindowtitle

  if (!($vischk)) 
  {
  Write-Warning "Security notice not present"
  } else {
  Write-Warning "This is where you'd do your scripting"
  }