|
-
Jul 7th, 2001, 05:56 PM
#1
Thread Starter
Member
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.
-
Jul 7th, 2001, 07:07 PM
#2
PowerPoster
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:
Public Const TH32CS_SNAPPROCESS As Long = 2&
Public Const MAX_PATH As Integer = 260
Public Type PROCESSENTRY32
dwSize As Long
cntUsage As Long
th32ProcessID As Long
th32DefaultHeapID As Long
th32ModuleID As Long
cntThreads As Long
th32ParentProcessID As Long
pcPriClassBase As Long
dwFlags As Long
szExeFile As String * MAX_PATH
End Type
Public Declare Function CreateToolhelpSnapshot Lib "Kernel32" Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, ByVal lProcessID As Long) As Long
Public Declare Function ProcessFirst Lib "Kernel32" Alias "Process32First" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Public Declare Function ProcessNext Lib "Kernel32" Alias "Process32Next" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
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:
Dim hSnapShot As Long
Dim uProcess As PROCESSENTRY32
Dim r As Long
hSnapShot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&)
If hSnapShot = 0 Then
Exit Sub
End If
uProcess.dwSize = Len(uProcess)
r = ProcessFirst(hSnapShot, uProcess)
Do While r
List1.AddItem uProcess.szExeFile
r = ProcessNext(hSnapShot, uProcess)
Loop
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:
Do While r
If InStr(1, uProcess.szExeFile, "IEXPLORE.EXE", vbTextCompare) > 0 Then
MsgBox "Internet Explorer is running!", vbInformation
End If
r = ProcessNext(hSnapShot, uProcess)
Loop
Last edited by chrisjk; Jul 7th, 2001 at 07:13 PM.
-
Jul 7th, 2001, 07:55 PM
#3
Thread Starter
Member
Sweet! thanks for the assist.
-
Jul 8th, 2001, 01:31 AM
#4
Registered User
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.
-
Jul 8th, 2001, 07:20 AM
#5
Thread Starter
Member
chuckle.. interestingly enough.. it runs in the background... so yes.. it is windowless.
-
Jul 8th, 2001, 07:29 AM
#6
Frenzied Member
Bishop -
Did you ever figure out that right-click in WebBrower Control problem?
-
Jul 8th, 2001, 08:58 AM
#7
Thread Starter
Member
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?
-
Jul 8th, 2001, 09:46 AM
#8
Frenzied Member
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.
-
Jul 8th, 2001, 10:33 AM
#9
Thread Starter
Member
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.
-
Jul 8th, 2001, 11:13 AM
#10
Frenzied Member
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?
-
Jul 8th, 2001, 11:25 AM
#11
Thread Starter
Member
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.
-
Jul 8th, 2001, 11:36 AM
#12
Frenzied Member
Hey thanks, should have known it was going to be something simple.
Have you resolved your problem concerning this post?
-
Jul 8th, 2001, 11:43 AM
#13
Thread Starter
Member
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.
-
Jul 8th, 2001, 02:10 PM
#14
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|