Results 1 to 14 of 14

Thread: [RESOLVED] Identifying if another Application is currently in memory?

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2001
    Location
    Toronto, Ontario, Canada
    Posts
    56

    Identifying if another Application is currently in memory?

    Is there a way to detect if an application is currently running by just it's name? Sort of like how the Windows Task Manager lists all programs running at the time... but I'm only looking for one specific program.

  2. #2
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923
    This will list all running processes (that includes EXE's, DLL's etc). Add a List box (List1) and a command button to a form. Paste this code into a module
    VB Code:
    1. Public Const TH32CS_SNAPPROCESS As Long = 2&
    2. Public Const MAX_PATH As Integer = 260
    3.  
    4. Public Type PROCESSENTRY32
    5.     dwSize As Long
    6.     cntUsage As Long
    7.     th32ProcessID As Long
    8.     th32DefaultHeapID As Long
    9.     th32ModuleID As Long
    10.     cntThreads As Long
    11.     th32ParentProcessID As Long
    12.     pcPriClassBase As Long
    13.     dwFlags As Long
    14.     szExeFile As String * MAX_PATH
    15. End Type
    16.  
    17. Public Declare Function CreateToolhelpSnapshot Lib "Kernel32" Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, ByVal lProcessID As Long) As Long
    18. Public Declare Function ProcessFirst Lib "Kernel32" Alias "Process32First" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
    19. Public Declare Function ProcessNext Lib "Kernel32" Alias "Process32Next" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
    20. Public Declare Sub CloseHandle Lib "Kernel32" (ByVal hPass As Long)
    Then place this in the click event of the command button on the form
    VB Code:
    1. Dim hSnapShot As Long
    2. Dim uProcess As PROCESSENTRY32
    3. Dim r As Long
    4.  
    5. hSnapShot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&)
    6.  
    7. If hSnapShot = 0 Then
    8.     Exit Sub
    9. End If
    10.  
    11. uProcess.dwSize = Len(uProcess)
    12. r = ProcessFirst(hSnapShot, uProcess)
    13.  
    14. Do While r
    15.     List1.AddItem uProcess.szExeFile
    16.     r = ProcessNext(hSnapShot, uProcess)
    17. Loop
    18.  
    19. Call CloseHandle(hSnapShot)
    You can then modify it to suit what you need...for example to see if IE is open, modify the Do Loop like so...
    VB Code:
    1. Do While r
    2.     If InStr(1, uProcess.szExeFile, "IEXPLORE.EXE", vbTextCompare) > 0 Then
    3.         MsgBox "Internet Explorer is running!", vbInformation
    4.     End If
    5.     r = ProcessNext(hSnapShot, uProcess)
    6. Loop
    Last edited by chrisjk; Jul 7th, 2001 at 07:13 PM.

  3. #3

    Thread Starter
    Member
    Join Date
    Jun 2001
    Location
    Toronto, Ontario, Canada
    Posts
    56
    Sweet! thanks for the assist.

  4. #4
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    Perhaps you could also use findwindow win32API or findwindowex win32API functions and pass the class name and or the window caption?

    This should work unless the app is windowless.

  5. #5

    Thread Starter
    Member
    Join Date
    Jun 2001
    Location
    Toronto, Ontario, Canada
    Posts
    56
    chuckle.. interestingly enough.. it runs in the background... so yes.. it is windowless.

  6. #6
    Frenzied Member
    Join Date
    Mar 2001
    Location
    You are HERE •™
    Posts
    1,300
    Bishop -

    Did you ever figure out that right-click in WebBrower Control problem?

  7. #7

    Thread Starter
    Member
    Join Date
    Jun 2001
    Location
    Toronto, Ontario, Canada
    Posts
    56
    Hey Bloodeye!

    Yeah... I successfully managed to catch all the keystroke issues as well as capture the right click event and replace the context menu with a custom Copy and Paste menu....

    I'm currently working on another part of the application that requires me to kill another running process that the program did not originally spawn.

    I've got the process detecting code (as from this thread and Microsoft). Microsoft had an Win9x/ME/2K/NT solution.... Now I just need a Win9x/ME/2K/NT solution to forceful killing the found process by PID...

    Any suggestions?

  8. #8
    Frenzied Member
    Join Date
    Mar 2001
    Location
    You are HERE •™
    Posts
    1,300
    I just did a search on this board for "kill running process", and found this link. Maybe it will help.
    http://forums.vb-world.net/showthrea...threadid=48419

    BTW: If it's not too much could you post the entire code, or a demo project for the right-click issue. I think I may have some use for that.

  9. #9

    Thread Starter
    Member
    Join Date
    Jun 2001
    Location
    Toronto, Ontario, Canada
    Posts
    56
    Hey.. no problem.. but what exactly did you want from the project?

    If you looking for the Rightclick issue, the code was from here:
    http://forums.vb-world.net/showthrea...INTAPI+disable

    That forms the core of the Mouse solution...

    The Keyboard solution you and Ryebread worked with me on at:

    http://forums.vb-world.net/showthrea...ght=webbrowser

    Plus the strategy for the right click context menu and hook on/off strategy are detailed in the 2nd listed discussion thread.

  10. #10
    Frenzied Member
    Join Date
    Mar 2001
    Location
    You are HERE •™
    Posts
    1,300
    The hook on/off strategy was never resolved. You had an attachment for that post (looks like now that you've deleted it) that didn't quite work. It would bomb when right-clicking on the WebBrowser and trying to display a custom context menu.

    What's the code to display your custom context menu? How exactly did you enable it correctly?

  11. #11

    Thread Starter
    Member
    Join Date
    Jun 2001
    Location
    Toronto, Ontario, Canada
    Posts
    56
    Oh.. that issue... that's easy..

    We created the Menu in the frmMain (that contained the browser) while the right click hook was located in a module.

    When you called the menu from the Module, you need to call it like so:
    frmMain.PopupMenu frmMain.mnuPopup

    What I forgot and what I had posted in the attachment (I assumed you were the one who downloaded it now) was:

    frmMain.PopupMenu mnuPopup

    That resulted in the Object not found - Hence the crash.

  12. #12
    Frenzied Member
    Join Date
    Mar 2001
    Location
    You are HERE •™
    Posts
    1,300
    Hey thanks, should have known it was going to be something simple.

    Have you resolved your problem concerning this post?

  13. #13

    Thread Starter
    Member
    Join Date
    Jun 2001
    Location
    Toronto, Ontario, Canada
    Posts
    56
    Yeah... I got some code from Microsoft for the List Process... however I'm still having problems with the Kill code... all the code that I've located is OS depedent... either 9x/Me or NT/2000.. I need a way that I can do both.

    Thanks for the link earlier.. but it didn't have material pertaining to the OS split I just mentioned.

  14. #14
    Frenzied Member
    Join Date
    Mar 2001
    Location
    You are HERE •™
    Posts
    1,300
    Maybe you could have code for both kernels. Then have code that determines what OS is being used when your program first starts, and store some value in the registry. Then have your code execute dependant on what that value is. Sometimes (rarely) code is OS dependant and won't work for both platforms. You might want to try posting this in the API section also.
    BTW: what exactly is it that you are trying to kill.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width