Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Determine if a Specific exe File is Running

Status
Not open for further replies.

dsi

Programmer
Mar 13, 2000
964
US
I know this has probably been answered already, but the Search did not find any results. I am looking for a simple way to find out if an exe file is running (VB6 NT4-SP6). Any help is greatly appreciated.
 
have you tried the FindWindow() API command? you can find a window using either the caption on the program, or it's classname, then it'll return a handle to that window, from there you can modify anything, if it returns null(or false) Then that caption, or classname is not running. <p>Karl<br><a href=mailto:kb244@kb244.8m.com>kb244@kb244.8m.com</a><br><a href= </a><br>Experienced in , or have messed with : VC++, Borland C++ Builder, VJ++6(starting),VB-Dos, VB1 thru VB6, Delphi 3 pro, Borland C++ 3(DOS), Borland C++ 4.5, HTML,Visual InterDev 6, ASP(WebProgramming), QBasic(least i didnt start with COBOL)
 
Unfortunately, the application that I am looking for does not have a constant caption. The application I am trying to pin down is another VB utility that I have written for our 3-D modeling software. It is just a standard exe program. How would I find it using the classname? I have done this before using XLMAIN for Excel, but I am not sure how to go about it with this application.<br><br>Thanks
 
do you know the classname of the application? (almost all exe have a classname) <p>Karl<br><a href=mailto:kb244@kb244.8m.com>kb244@kb244.8m.com</a><br><a href= </a><br>Experienced in , or have messed with : VC++, Borland C++ Builder, VJ++6(starting),VB-Dos, VB1 thru VB6, Delphi 3 pro, Borland C++ 3(DOS), Borland C++ 4.5, HTML,Visual InterDev 6, ASP(WebProgramming), QBasic(least i didnt start with COBOL)
 
far as classname goes, like IE when you use Spy++ (comes with Visual Studio) use Find window, and move the target over a unique part of the window, like with IE if I put it over this HTML view part the classname is Internet Explorer_Server, the classname of the frame is IEFrame., your program might have something similiar. <p>Karl<br><a href=mailto:kb244@kb244.8m.com>kb244@kb244.8m.com</a><br><a href= </a><br>Experienced in , or have messed with : VC++, Borland C++ Builder, VJ++6(starting),VB-Dos, VB1 thru VB6, Delphi 3 pro, Borland C++ 3(DOS), Borland C++ 4.5, HTML,Visual InterDev 6, ASP(WebProgramming), QBasic(least i didnt start with COBOL)
 
That would be too easy. I do not have the complete Visual Studio package. When making a standard exe program, can you specify/define the classname? I can see the process in Task Manager. I have found code to list all of the running processes. It just seems a bit long for my needs. I will keep pecking around for something simpler like: IsThisDarnAppRunning(&quot;something.exe&quot;)<br><br><A HREF=" TARGET="_new">
 
nope, the exe name cannot be specified, mainly because the filename has nothing to do with the application itself, you could have the same application with different filenames, still wouldnt make a difference. you might have it under /visual studio 6 tools , you may have spy++ , if not I can write you can application that shows you the classname of whatever your mouse is over. <p>Karl<br><a href=mailto:kb244@kb244.8m.com>kb244@kb244.8m.com</a><br><a href= </a><br>Experienced in , or have messed with : VC++, Borland C++ Builder, VJ++6(starting),VB-Dos, VB1 thru VB6, Delphi 3 pro, Borland C++ 3(DOS), Borland C++ 4.5, HTML,Visual InterDev 6, ASP(WebProgramming), QBasic(least i didnt start with COBOL)
 
No, I do not have spy*.* on my machine. I do appreciate the offer to help me out, but I do not think that is required. The routine I found requires psapi.dll which I do not have either. I can just have the one app set up a flag which the other app can read. I was just trying to avoid messing with the other application. I guess it all pays the same! Thanks anyway!
 
I found a solution in vb-world.net. I was looking for FILENAME.exe and just checked: If TaskName Like &quot;FILENAME&quot;. To list all running apps, create a new project, add a command button and a listbox, then insert this code. <br><br>Private Declare Function GetWindow Lib &quot;user32&quot; (ByVal hwnd As Long, ByVal wCmd As Long) As Long<br>Private Declare Function GetParent Lib &quot;user32&quot; (ByVal hwnd As Long) As Long<br>Private Declare Function GetWindowTextLength Lib &quot;user32&quot; Alias &quot;GetWindowTextLengthA&quot; (ByVal hwnd As Long) As Long<br>Private Declare Function GetWindowText Lib &quot;user32&quot; Alias &quot;GetWindowTextA&quot; (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long<br>Const GW_HWNDFIRST = 0<br>Const GW_HWNDNEXT = 2<br>Private Sub Command1_Click()<br>&nbsp;&nbsp;&nbsp;&nbsp;LoadTaskList<br>End Sub<br>Sub LoadTaskList()<br>&nbsp;&nbsp;&nbsp;&nbsp;Dim CurrWnd As Long<br>&nbsp;&nbsp;&nbsp;&nbsp;Dim Length As Long<br>&nbsp;&nbsp;&nbsp;&nbsp;Dim TaskName As String<br>&nbsp;&nbsp;&nbsp;&nbsp;Dim Parent As Long<br>&nbsp;&nbsp;&nbsp;&nbsp;List1.Clear<br>&nbsp;&nbsp;&nbsp;&nbsp;CurrWnd = GetWindow(Form1.hwnd, GW_HWNDFIRST)<br>&nbsp;&nbsp;&nbsp;&nbsp;While CurrWnd &lt;&gt; 0<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Parent = GetParent(CurrWnd)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Length = GetWindowTextLength(CurrWnd)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TaskName = Space$(Length + 1)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Length = GetWindowText(CurrWnd, TaskName, Length + 1)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TaskName = Left$(TaskName, Len(TaskName) - 1)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If Length &gt; 0 Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If TaskName &lt;&gt; Me.Caption Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;List1.AddItem TaskName<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;End If<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;End If<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CurrWnd = GetWindow(CurrWnd, GW_HWNDNEXT)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DoEvents<br>&nbsp;&nbsp;&nbsp;&nbsp;Wend<br>End Sub<br><br>Once again, thanks for your help!<br>
 
ah yes vb-world, been there before several times. <p>Karl<br><a href=mailto:kb244@kb244.8m.com>kb244@kb244.8m.com</a><br><a href= </a><br>Experienced in , or have messed with : VC++, Borland C++ Builder, VJ++6(starting),VB-Dos, VB1 thru VB6, Delphi 3 pro, Borland C++ 3(DOS), Borland C++ 4.5, HTML,Visual InterDev 6, ASP(WebProgramming), QBasic(least i didnt start with COBOL)
 
tclere - you should turn that answer into a FAQ <p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>Please -- Don't send me email questions without posting them in Tek-Tips as well. Better yet -- Post the question in Tek-Tips and send me a note saying "Have a look at so-and-so in the thingy forum would you?"
 
Add this one to your tool box. It returns the physical path and filename of any EXE or DLL running on a system.<br>You'll need a command button and a list box:<br><br>Public Const TH32CS_SNAPPROCESS As Long = 2&<br>Public Const MAX_PATH As Integer = 260<br>Public Type PROCESSENTRY32<br>&nbsp;&nbsp;&nbsp;&nbsp;dwSize As Long<br>&nbsp;&nbsp;&nbsp;&nbsp;cntUsage As Long<br>&nbsp;&nbsp;&nbsp;&nbsp;th32ProcessID As Long<br>&nbsp;&nbsp;&nbsp;&nbsp;th32DefaultHeapID As Long<br>&nbsp;&nbsp;&nbsp;&nbsp;th32ModuleID As Long<br>&nbsp;&nbsp;&nbsp;&nbsp;cntThreads As Long<br>&nbsp;&nbsp;&nbsp;&nbsp;th32ParentProcessID As Long<br>&nbsp;&nbsp;&nbsp;&nbsp;pcPriClassBase As Long<br>&nbsp;&nbsp;&nbsp;&nbsp;dwFlags As Long<br>&nbsp;&nbsp;&nbsp;&nbsp;szExeFile As String * MAX_PATH<br>End Type<br>Public Declare Function CreateToolhelpSnapshot Lib &quot;Kernel32&quot; Alias _<br>&quot;CreateToolhelp32Snapshot&quot; (ByVal lFlags As Long, ByVal lProcessID As Long) As Long<br>Public Declare Function ProcessFirst Lib &quot;Kernel32&quot; Alias &quot;Process32First&quot; _<br>(ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long<br>Public Declare Function ProcessNext Lib &quot;Kernel32&quot; Alias &quot;Process32Next&quot; _<br>(ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long<br>Public Declare Sub CloseHandle Lib &quot;Kernel32&quot; (ByVal hPass As Long)<br><br>Private Sub Command1_Click()<br>Dim hSnapShot As Long<br>Dim uProcess As PROCESSENTRY32<br>Dim r As Long<br>hSnapShot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&)<br>If hSnapShot = 0 Then<br>&nbsp;&nbsp;&nbsp;&nbsp;Exit Sub<br>End If<br>uProcess.dwSize = Len(uProcess)<br>r = ProcessFirst(hSnapShot, uProcess)<br>Do While r<br>&nbsp;&nbsp;&nbsp;&nbsp;List1.AddItem uProcess.szExeFile<br>&nbsp;&nbsp;&nbsp;&nbsp;r = ProcessNext(hSnapShot, uProcess)<br>Loop<br>Call CloseHandle(hSnapShot)<br>End Sub<br><br> <p> <br><a href=mailto: > </a><br><a href= plain black box</a><br>
 
Thanks for all the help. I have submitted a FAQ with both solutions, giving credit where credit is due.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top