0

I would like to know if it is possible to detect when the window of a named external application is launched and how to.

Example: When firefox or notepad(preferably by process name. Not notepad.exe for example) is ran, minimize my application.

Filburt
  • 17,626
  • 12
  • 64
  • 115
Rick
  • 1
  • 1

2 Answers2

1
For each p as process in process.GetProcesses()
If p.processname = "notepad" then
'Do something
Else
'Do Else Something
End If
Next
SomeNickName
  • 511
  • 6
  • 32
  • Well that will do 'something else' for EVERY process in the list that is NOT 'notepad' ... – MrPaulch Dec 08 '13 at 22:57
  • 1
    Not if you leave 'Do Else Something commented out. – Steve Rindsberg Dec 09 '13 at 00:47
  • Yea, right... but then you could relable it: 'do nothing // Also if there are several processes of notepad running the 'do something part will be runned as many times... of course you could leave that one commented out aswell :) – MrPaulch Dec 09 '13 at 01:00
  • That was careless in my part, good point, may i edit and put an Exit For after the 'Do something? ;) – SomeNickName Dec 09 '13 at 01:13
1

Here two ways, that would work:

 Dim plist() As Process = Process.GetProcessesByName("notepad")
 If plist.Length > 0 Then
      ' notepad is running at least once
 Else
      ' notepad is not running
 End If

or

    Dim notepadRunning As Boolean = False
    For Each p As Process In Process.GetProcesses
        If p.ProcessName = "notepad" Then notepadRunning = True
    Next
    If notepadRunning Then
        ' notepad is running at least once
    Else
        'notepad is not running
    End If

Note: the second way is just a glorified version of the first...

MrPaulch
  • 1,423
  • 17
  • 21