How to cancel lunching application from the beginning?

awsok

Member
Joined
Mar 3, 2005
Messages
8
Programming Experience
1-3
Hi



I am making a VB application and want to give the users ability to CANCEL lunching the application depending on whether a process (instance of INTERNET EXPLORER) is already running or not?

So sending a MessageBox with Yes, No and CANCEL is probably the way, but HOW?


Any idea please?
 

Eric_Mutta

Member
Joined
Mar 30, 2005
Messages
5
Location
UK
Programming Experience
5-10
You mean you want users to start your app then if Internet Explorer is running you want them to choose whether or not to continue running your app? Is this correct?
 

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,524
Location
Lansing, MI; USA
Programming Experience
10+
the code for the messagebox spec's may be wrong as i didnt bother checking it with the VS editor but this is roughly what yer looking for:

VB.NET:
Dim dlgResult as DialogResult
dlgResult = Messagebox.Show("Close Internet Explorer?", "Close IE", MessageboxButtons.YesNo)

If dlgResult = DialogResult.Yes Then
  Call KillProcess("IExplore")
End If

End Sub

Friend Sub KillProcess(ByVal ProcessName As String)
		Dim prc() As Process
		Dim ERROR_FILE_NOT_FOUND As Integer = 2
		Dim ERROR_ACCESS_DENIED As Integer = 5
		Try
			prc = System.Diagnostics.Process.GetProcessesByName(ProcessName)
			Dim eprc As IEnumerator = prc.GetEnumerator
			eprc.Reset()

			While eprc.MoveNext
			    Dim proc As Process = CType(eprc.Current, Process)
				proc.Kill()
				proc = Nothing
			End While

			eprc = Nothing
			prc = Nothing

		Catch e As System.ComponentModel.Win32Exception
			If e.NativeErrorCode = ERROR_FILE_NOT_FOUND Then
			    'MessageBox.Show(e.Message + ". Process not found.")
			    Throw New UnauthorizedAccessException(e.Message & ". Process not found.")
			Else
			    If e.NativeErrorCode = ERROR_ACCESS_DENIED Then
				    ' Note that if your word processor might generate exceptions 
				    ' such as this, which are handled first. 
				    'MessageBox.Show(e.Message + ". You do not have permission to kill this process.")
				    Throw New UnauthorizedAccessException(e.Message & ". You do not have permission to kill this process.")
				End If
			End If
		End Try
	End Sub
is something that you want, this will close ALL IE windows though
 

awsok

Member
Joined
Mar 3, 2005
Messages
8
Programming Experience
1-3
Yes exactly...

Yes
I want to let the user choose from 3
1- lunch the Application, after closing all running IE (Yes)
2- lunch the Application, and leaving all running IE (No)
3- not lunching the Application at all if some IE was running (CANCEL) MOST IMPORTANT... How

Thanks for the interest
 
Top Bottom