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.
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.
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 moduleThen place this in the click event of the command button on the formVB 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)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:
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)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
Sweet! thanks for the assist.
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.
chuckle.. interestingly enough.. it runs in the background... so yes.. it is windowless.
Bishop -
Did you ever figure out that right-click in WebBrower Control problem?
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?
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.
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.
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?
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.
Hey thanks, should have known it was going to be something simple.
Have you resolved your problem concerning this post?
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.
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.