Run Program only once

  • Thread starter Thread starter Josh Burkard
  • Start date Start date
J

Josh Burkard

Hello

How can i control, that a user can't start my VB.Net-Program 2 ore more times at once (maybee like Outlook)?

At same time Parameters which are transfered with the second program should be transfered to the first program.

Best regards
Josh
 
If you are using VB2005, it's built in. Open the project's properties panel
(Project --> WindowsApplication1 Properties), select the Application tab,
make sure that "Enable application framework" is selected, and then select
"Make single instance application." To process the incoming arguments for
subsequent startups, click the "View Application Events" button on that same
panel. In the code file that appears, add an event handler for MyApplication_StartupNextInstance.
In that handler, the e.CommandLine property gives you access to the new command
line.
 
This is what I use for VB.NET 2003:

#Region "Previous Existance Function"
' Previous Existance function
Private Function PrevInstance() As Boolean
' Check to see if another existance of the assembly is found
If UBound(System.Diagnostics.Process.GetProcessesByName(System.Diagnostics.Process.GetCurrentProcess.ProcessName)) > 0 Then
' Yes, it was - return true
Return True
' No previous existance found - return false
Else
Return False
End If
End Function

#End Region

Usage:

' Check for previous existance of the application
If PrevInstance() = True Then
' Display a message box if a previous existance exists
MessageBox.Show("The application is already running. Press OK to exit", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
' End the application (see note at bottom of header above)
End
End If

I hope this helps,

Newbie Coder
Hello

How can i control, that a user can't start my VB.Net-Program 2 ore more times at once (maybee like Outlook)?

At same time Parameters which are transfered with the second program should be transfered to the first program.

Best regards
Josh
 
Josh,

Rereading the excelent answer from Tim, if it is for versions before 2005 than is this in my idea the best result from endless discussion about this question on this board.

http://www.vb-tips.com/dbpages.aspx?ID=59135549-e5dd-4501-9526-343ac05a7617

Keep in mind that our website is under construction at the moment

Cor

"Josh Burkard" <[email protected]> schreef in bericht Hello

How can i control, that a user can't start my VB.Net-Program 2 ore more times at once (maybee like Outlook)?

At same time Parameters which are transfered with the second program should be transfered to the first program.

Best regards
Josh
 
Thanks & Best Regards

Josh

Tim Patrick said:
If you are using VB2005, it's built in. Open the project's properties
panel (Project --> WindowsApplication1 Properties), select the Application
tab, make sure that "Enable application framework" is selected, and then
select "Make single instance application." To process the incoming
arguments for subsequent startups, click the "View Application Events"
button on that same panel. In the code file that appears, add an event
handler for MyApplication_StartupNextInstance. In that handler, the
e.CommandLine property gives you access to the new command line.
 
Back
Top