exit program when setup is running

ud2008

Well-known member
Joined
Jul 5, 2010
Messages
148
Programming Experience
Beginner
I've created a program with vb2010 and I am kinda stuck with the following:

When I run the program it checks if there is an update for it, if so, then the exe is downloaded and is executed, the program (main program) then checks if the setup is running, if so the program quits so the setup can continue.

But at this point, everything works fine, until the point that the setup is executed, the program keeps running (the splashscreen starts), while it should stop.

Here is the code I use:
VB.NET:
Public Shared Function isprocessrunning(ByVal name As String) As Boolean
	For Each proc As Process In Process.GetProcesses
		If proc.ProcessName.StartsWith(name) Then
			Return True
		End If
	Next
	Return False
End Function

Public Shared Sub KillApp(ByRef strProcessToKill As String)
	Dim proc() As Process = Process.GetProcesses
	For i As Integer = 0 To proc.GetUpperBound(0)
		If proc(i).ProcessName = strProcessToKill Then
			proc(i).Kill()
		End If
	Next
End Sub

Private Sub SplashScreen1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
	If isprocessrunning("Songlist Editor 2 setup") Then
		Dim button As DialogResult
		button = MessageBox.Show _
			("Setup is running, please close application!", _
			 "Songlist Editor 2", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
		If button = Windows.Forms.DialogResult.OK Then
			'MessageBox.Show("setup is running, please close application!")
			KillApp("Songlist Editor 2")
		End If
	End If
End Sub
At start (if the setup is running) the message of setup is running is shown. But the program continues to start.

Any suggestions are welcome.
 
oh and also, in the for cycle, add a line to show a messagebox when it matches strProcessToKill

If proc(i).ProcessName = strProcessToKill Then
MessageBox.Show("OK I'm sure it found my proc")
proc(i).Kill()
End If
 
oh and also, in the for cycle, add a line to show a messagebox when it matches strProcessToKill

If proc(i).ProcessName = strProcessToKill Then
MessageBox.Show("OK I'm sure it found my proc")
proc(i).Kill()
End If

That didn't work, the messagebox isn't showing. so it's not being found.
 
it's actually: StartsWith("your proc name") ;) but that didn't work either, the message of MessageBox.Show("OK I'm sure it found my proc") isn't shown at all.
 
Oh sorry it did work, but when I debugged it in vs2010, the exe wasn't showing, when I run the app outside vs2010 I got the message and it was exit.
 
I think you are just thinking the wrong way around... The setup program should detect that the application is running and offer to shut it down, not the other way around.
 
maybe when it runs in debug mode, the proc has a different name than the real name it should assume in normal runtime, so it was not found
by the way, yes I meant to say StartsWith("your proc name") XD
 
Back
Top