Do not use on any
shared computer
May 17, 2008 06:30am pdt
05.05.2008 at 10:58AM PDT, ID: 23377134
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

window forms and launch restrictions in visual basic 2005
I am developing with visual basic 2005 and would like to know how to prevent MY application from launching more than once.  For instance, I install the software on my system, then launch it from the desktop and it opens up correctly.  Then while this first instance is opened, I double click on the shortcut again and the application is running a second instance.
What will be a method within code that will restrict the application to only 1 instance, meaning if I have the software opened, and then launch it again from the short cut, it will detect that the software is currently running and not open this second instance and maybe flash the main screen to the user (form.activate)
Thank you
Start your free trial to view this solution
Question Stats
Zone: Microsoft
Question Asked By: systems_ax
Solution Provided By: Idle_Mind
Participating Experts: 2
Solution Grade: A
Views: 0
Translate:
Loading Advertisement...
05.05.2008 at 11:01AM PDT, ID: 21501738

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.05.2008 at 11:52AM PDT, ID: 21502118

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.05.2008 at 11:55AM PDT, ID: 21502139

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.06.2008 at 09:16AM PDT, ID: 21508583

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.06.2008 at 09:28AM PDT, ID: 21508688

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.06.2008 at 10:07AM PDT, ID: 21509067

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.06.2008 at 10:45AM PDT, ID: 21509381

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.06.2008 at 10:58AM PDT, ID: 21509471

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.06.2008 at 11:06AM PDT, ID: 21509534

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.06.2008 at 11:21AM PDT, ID: 21509633

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.08.2008 at 01:54PM PDT, ID: 21528383

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.08.2008 at 02:32PM PDT, ID: 21528655

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.08.2008 at 02:51PM PDT, ID: 21528774

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.08.2008 at 02:53PM PDT, ID: 21528795

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.08.2008 at 03:42PM PDT, ID: 21529073

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.08.2008 at 03:48PM PDT, ID: 21529099

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Handhelds / PDAs
  • Displays / Monitors
  • Components
  • Networking Hardware
  • Peripherals
  • Laptops/Notebooks
  • Storage
  • Servers
  • Desktops
  • New Users
  • Misc
  • Apple
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMWare
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMWare
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Community Advisor
  • Lounge
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • Community Advisor
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
05.05.2008 at 11:01AM PDT, ID: 21501738
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
The PrevInstance() function is from the helpfile:
 
Public Class Form3
    Inherits System.Windows.Forms.Form
 
    Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If PrevInstance() Then
            Application.Exit()
        End If
    End Sub
 
    Private Function PrevInstance() As Boolean
        If UBound(Diagnostics.Process.GetProcessesByName(Diagnostics.Process.GetCurrentProcess.ProcessName)) > 0 Then
            Return True
        Else
            Return False
        End If
    End Function
 
End Class
Open in New Window
 
05.05.2008 at 11:52AM PDT, ID: 21502118

Rank: Genius

There is a cleaner, newer method available in VB.Net 2005 (or above).

Just click on Project --> Properties, then on the Application Tab make sure the "Make single instance application" box is CHECKED.

You're done!
Accepted Solution
 
05.05.2008 at 11:55AM PDT, ID: 21502139

Rank: Genius

If you need something special to happen on subsequent launches see the StartupNextInstance() event:
"My.Application.StartupNextInstance Event"
http://msdn.microsoft.com/en-us/library/b9z4eyh8.aspx
 
05.06.2008 at 09:16AM PDT, ID: 21508583
Idle_MInd,
it does work with the:
Just click on Project --> Properties, then on the Application Tab make sure the "Make single instance application" box is CHECKED.

But apparently when my main form launches and then I simply minimize it and try to run the same application from he shortcut again, my main screen that is minimized shrinks and is placed to the upper right corner.  What I need it to do is either for it to stay minimized or for it to maximize in a center of the screen.
thank you
 
05.06.2008 at 09:28AM PDT, ID: 21508688
pollock_d,
is there a way to change the "Application.Exit()" to something else.  Because I implement a try/catch into my splash screen code, I need to implement something like this:

but what happens is that when I launch the shortcut second time while app is still opened, my splash screen appears and then di-ssapears.  is there a way for it not to display at all and just not do anything.  So,what I am trying to convey is that I do not need anything to occur when I try to launch the second instance of the application.  I only need for the second instance not launch that is all.  so if I have one instance of my app already running and try to run it again, nothing is expected to show, just the second instance does not launch.
Thanks you
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
Private Sub SplashScreen1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
 
 
        ' ''Try
        ' ''    If PrevInstance() Then
        ' ''        'Application.Exit()
        ' ''    Else
        ' ''        '    Main.Show()
 
 
 
 
        Dim regKey(1) As Microsoft.Win32.RegistryKey
        regKey(0) = My.Computer.Registry.CurrentUser.OpenSubKey("Software\Adobe", False)
        regKey(1) = My.Computer.Registry.LocalMachine.OpenSubKey("SOFTWARE\Adobe", False)
        Dim paths As New List(Of String)
        For idx As Integer = 0 To 1
            If regKey(idx) IsNot Nothing Then
                paths.AddRange(regKey(idx).GetSubKeyNames())
            End If
        Next
        Dim path As String
        Dim installed As Boolean = False
        For Each path In paths
            If path = "Acrobat Reader" Or path = "Acrobat" Or path = "Adobe Acrobat" Then
                installed = True
            End If
        Next
        If regKey(0) IsNot Nothing Then
            regKey(0).Close()
        End If
        If regKey(1) IsNot Nothing Then
            regKey(1).Close()
        End If
        'regKey(0).Close()
        'regKey(1).Close()
        If installed Then
            myTimer = New Timer
            myTimer.Interval = 2000
            myTimer.Enabled = True
            AddHandler myTimer.Tick, AddressOf DoTimerWork
        Else
            If MessageBox.Show("Adobe Acrobat Reader is not installed, would you like to install now?", "Acrobat Reader", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
                System.Diagnostics.Process.Start("Documentation\Setup.exe")
                End
            Else
                myTimer = New Timer
                myTimer.Interval = 2000
                myTimer.Enabled = True
                AddHandler myTimer.Tick, AddressOf DoTimerWork
            End If
        End If
 
        ' ''    End If
 
        ' ''Catch ex As Exception
 
        ' ''End Try
    End Sub
Open in New Window
 
05.06.2008 at 10:07AM PDT, ID: 21509067

Rank: Genius

"But apparently when my main form launches and then I simply minimize it and try to run the same application from he shortcut again, my main screen that is minimized shrinks and is placed to the upper right corner.  What I need it to do is either for it to stay minimized or for it to maximize in a center of the screen."

I don't know why that is happening...on my system the app just blinks in the TaskBar.

When the box is checked and you don't do anything in the StartupNextInstance() event then the second instance just dies and it does NOTHING to the first instance unless you specifically coded it to do so...
 
05.06.2008 at 10:45AM PDT, ID: 21509381
Idle_Mind,
is there a property that I could have set to the Main form that you know of that can cause that issue.
I have not set anything in code for it to behave this way.
thank you
 
05.06.2008 at 10:58AM PDT, ID: 21509471

Rank: Genius

Nothing that I can think of at the moment...  =\

I suggest you create a New, Blank Project, set the "Make single instance application" box and run it to see what happens.  Perhaps you have your Operating System set differently?  This will at least tell us if it is something specific to that app or something OS wide.
 
05.06.2008 at 11:06AM PDT, ID: 21509534
Idle_Mind,
this is what I have:

Enable application framework is checked
Enable XP visual styles is checked
Save me.settings on shutdown is checked
Authentication mode: Windows

should I set the authen. mode to application defined?
I will try it thanks


 
05.06.2008 at 11:21AM PDT, ID: 21509633

Rank: Genius

"should I set the authen. mode to application defined?"

To be honest, I've never changed that value!

I don't see how it would cause the symptoms though:
http://msdn.microsoft.com/en-us/library/tzdks800.aspx

    "Select Windows (the default) to specify the use of Windows authentication to identify the currently logged-on user. You can retrieve this information at run time by using the My.User object. Select Application-defined if you will provide your own code to authenticate users instead of using the default Windows authentication methods."
 
05.08.2008 at 01:54PM PDT, ID: 21528383
Idle_Mind,
could it be that my main form is not a startup form, I have a splash as a startup form.
can that be the problem?
thank you

I have tried with a newly created form and it still jumps from being minimized to upper left.
 
05.08.2008 at 02:32PM PDT, ID: 21528655

Rank: Genius

That is possible.  Why do you have the splash as the startup form?

...and how are you then showing the main form?
 
05.08.2008 at 02:51PM PDT, ID: 21528774
Idle_Mind,
I need the splash to be a startup form, it is a requirement for my program.  is there a hard coded function that can be applied to the main form which is not a start up form.
thank you
 
05.08.2008 at 02:53PM PDT, ID: 21528795

Rank: Genius

Ok...what is the "requirement"?

Tell me more.  Perhaps there is a different way to achieve the same end result...
 
05.08.2008 at 03:42PM PDT, ID: 21529073
i have 2 forms, 1 is a splash screen (which is a start up form) and second is the "mainform".
I have included everything I have on my splash screen form, my main form has a few links on it that point to other forms.
thank you
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
Private Sub SplashScreen1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim regKey(1) As Microsoft.Win32.RegistryKey
        regKey(0) = My.Computer.Registry.CurrentUser.OpenSubKey("Software\Adobe", False)
        regKey(1) = My.Computer.Registry.LocalMachine.OpenSubKey("SOFTWARE\Adobe", False)
        Dim paths As New List(Of String)
        For idx As Integer = 0 To 1
            If regKey(idx) IsNot Nothing Then
                paths.AddRange(regKey(idx).GetSubKeyNames())
            End If
        Next
        Dim path As String
        Dim installed As Boolean = False
        For Each path In paths
            If path = "Acrobat Reader" Or path = "Acrobat" Or path = "Adobe Acrobat" Then
                installed = True
            End If
        Next
        If regKey(0) IsNot Nothing Then
            regKey(0).Close()
        End If
        If regKey(1) IsNot Nothing Then
            regKey(1).Close()
        End If
       If installed Then
            myTimer = New Timer
            myTimer.Interval = 2000
            myTimer.Enabled = True
            AddHandler myTimer.Tick, AddressOf DoTimerWork
        Else
            If MessageBox.Show("Adobe Acrobat Reader is not installed, would you like to install now?", "Acrobat Reader", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
                System.Diagnostics.Process.Start("Documentation\Setup.exe")
                End
            Else
                myTimer = New Timer
                myTimer.Interval = 2000
                myTimer.Enabled = True
                AddHandler myTimer.Tick, AddressOf DoTimerWork
            End If
        End If
   End Sub
 
 
Private Sub DoTimerWork(ByVal sender As Object, ByVal e As System.EventArgs)
        ' Stops the timer
        Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=test.mdb")
        Dim reader As OleDbDataReader
        myTimer.Enabled = False
        conn.Open()
        Dim query As String = "SELECT * FROM users"
        Dim cmd As OleDbCommand = New OleDbCommand(query, conn)
        reader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
              If reader.HasRows Then
            LoginUser.ShowDialog()
        Else
            Mainform.Show()
        End If
       Me.Close()
    End Sub
Open in New Window
 
05.08.2008 at 03:48PM PDT, ID: 21529099

Rank: Genius

That type of code should probably be in the Application.Startup() Event:
http://msdn.microsoft.com/en-us/library/w3xx6ewx.aspx
http://msdn.microsoft.com/en-us/library/t4zch4d2.aspx

Then you can leave the Splash form to, well, just "splash" itself with no code in it.
 
 
20080206-EE-VQP-25 / EE_QW_2_20070628