View Single Post
Old 03-25-2006, 08:52 AM
Mike Rosenblum's Avatar
Mike Rosenblum Mike Rosenblum is offline
Microsoft Excel MVP

Forum Leader
* Guru *
Join Date: Jul 2003
Location: New York, NY, USA
Posts: 7,848

Here's another approach that I think also appears to work cleanly:
''' <summary> ''' Tests whether an instance of the currently running Application is already running. ''' </summary> ''' <returns> ''' Returns 'True' if an instance of the current Application is already running. ''' </returns> ''' <remarks> ''' No parameters are passed into the function. IsAlreadyRunning() relies ''' on the Process.GetCurrentProcess() to determine if other Applications of the ''' same name and path location are already running. ''' </remarks> ''' <Author> Mike_R on </Author> ''' <Date> 2006.03.25 </Date> Public Shared Function IsAlreadyRunning() As Boolean Dim thisProcess As Process = Process.GetCurrentProcess Dim moduleName As String = thisProcess.MainModule.ModuleName Dim processName As String = System.IO.Path.GetFileNameWithoutExtension(moduleName) For Each p As Process In Process.GetProcessesByName(processName) If p.Id <> thisProcess.Id AndAlso _ p.MainModule.FileName = thisProcess.MainModule.FileName Then Return True End If Next p End Function
-- Mike
My Articles:
| Excel from .NET | Excel RibbonX using VBA | Excel from VB6 | CVErr in .NET | MVP |
Avatar by Lebb

Last edited by Mat Sumpter; 04-25-2007 at 01:33 PM.
Reply With Quote