Exetools  

Go Back   Exetools > General > General Discussion

Notices

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #3  
Old 05-24-2005, 15:22
surferxyz surferxyz is offline
Friend
 
Join Date: Jan 2005
Location: Planet Earth
Posts: 77
Rept. Given: 0
Rept. Rcvd 9 Times in 4 Posts
Thanks Given: 12
Thanks Rcvd at 54 Times in 21 Posts
surferxyz Reputation: 9
VB.Net

Code:
            '#Zone " Prevent multiple instances "
            If UBound(Diagnostics.Process.GetProcessesByName(Diagnostics.Process.GetCurrentProcess.ProcessName)) > 0 Then
                'Send opening form's TEXT property as a parameter to the function "ActivatePrevInstance"
                Dim PrevHndl As Long
                Dim result As Long
                Dim argStrAppToFind As String = "XXXXXXXXXXXXXXXX"
                'Variable to hold individual Process
                Dim objProcess As New Process
                'Collection of all the Processes running on local machine
                Dim objProcesses() As Process
                ''Get all processes into the collection
                objProcesses = Process.GetProcesses()

                For Each objProcess In objProcesses
                    ''Check and exit if we have SMS running already
                    If objProcess.MainWindowTitle.Length > 9 Or objProcess.MainWindowTitle = "xxxxxxxxxxxxxxxxxxxx" Then

                        If objProcess.MainWindowTitle = "xxxxxxxxxxxxxxxxxxxxxx" Then
                            MsgBox("Another instance of " & argStrAppToFind & " is already running on this machine. You cannot run TWO instances at a time. Please use the other instance.", MsgBoxStyle.Exclamation)
                            PrevHndl = objProcess.MainWindowHandle.ToInt32()
                            Exit For
                        End If
                        If (UCase(objProcess.MainWindowTitle.Substring(0, 12)) = UCase(argStrAppToFind)) Then
                            MsgBox("Another instance of " & argStrAppToFind & " is already running on this machine. You cannot run TWO instances at a time. Please use the other instance.", MsgBoxStyle.Exclamation)
                            PrevHndl = objProcess.MainWindowHandle.ToInt32()
                            Exit For
                        End If

                    End If
                Next
                If PrevHndl = 0 Then Exit Sub 'if No previous instance found exit the application.
                ''If found
                result = OpenIcon(PrevHndl) 'Restore the program.
                result = SetForegroundWindow(PrevHndl) 'Activate the application.

                End 'End the current instance of the application.
            End If
            '#End Zone
Reply With Quote
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[C] NoDel (tool to prevent file deletion) Insid3Code Source Code 0 02-10-2015 16:38
Prevent browser from being killed nino General Discussion 4 01-10-2014 02:38


All times are GMT +8. The time now is 00:43.


Always Your Best Friend: Aaron, JMI, ahmadmansoor, ZeNiX, chessgod101
( Since 1998 )