Connecting Tech Pros Worldwide Forums | Help | Site Map

Detecting windows processes.

chelf's Avatar
Member
 
Join Date: Jan 2007
Posts: 54
#1: 4 Weeks Ago
Hello,

Is there an API I can use to detect windows processes? For example, if I were to run notepad.exe, and I wanted to pop a message up in my program that said "notepad.exe" is running? How would I do that?

The real reason I want to do this is because I don't want my program interrupting me if certain programs are running, so if media player is running, I want my program to detect wmplayer.exe or whatever and disable itself.

Thanks!

Newbie
 
Join Date: Oct 2009
Posts: 31
#2: 4 Weeks Ago

re: Detecting windows processes.


Time to use your friends (yahoo, google, ask, answers, bing) for your needs as there are many examples out there including more than one at PSC (planet-source-code)...



Good Luck
chelf's Avatar
Member
 
Join Date: Jan 2007
Posts: 54
#3: 4 Weeks Ago

re: Detecting windows processes.


Umm thanks? Ok to those of you who want to know how to do this, here is a little program I wrote when I found out how to do it.

Expand|Select|Wrap|Line Numbers
  1. Dim WinProcesses() As String
  2. Dim WinProc As Object
  3. Dim WinProcSet As Object
  4. Dim WinProcCount As Long
  5. Dim CheckLoop As Long
  6. Private Sub cmdnotepad_Click()
  7. GetProcesses
  8. For CheckLoop = 1 To WinProcCount
  9.     If WinProcesses(CheckLoop) = "notepad.exe" Then
  10.         MsgBox "Notepad is running!"
  11.         Exit Sub
  12.     End If
  13. Next CheckLoop
  14. MsgBox "Notepad is not running!"
  15. End Sub
  16. Private Sub GetProcesses()
  17. WinProcCount = 0
  18. 'Count the processes to redim the array
  19. Set WinProcSet = GetObject("WinMgmts:").execquery("select * from Win32_process")
  20. For Each WinProc In WinProcSet
  21.     WinProcCount = WinProcCount + 1
  22. Next
  23.  
  24. 'Create the process list in an array
  25. ReDim WinProcesses(1 To WinProcCount) As String
  26. WinProcCount = 0
  27. For Each WinProc In WinProcSet
  28.     WinProcCount = WinProcCount + 1
  29.     WinProcesses(WinProcCount) = WinProc.Name
  30. Next
  31. End Sub
  32.  
If it's possible to check an array for a value without running a processor unfriendly loop, I'd like to know that if you don't mind.
Reply