Question VS2010 Program Launcher with Error Handler of some sort

Joined
May 12, 2011
Messages
8
Location
Cavite City, Philippines
Programming Experience
1-3
hello, i made a .exe launcher, i was able to launch a program named minecraft using the process.start. But this certain program generates error ussually, so what i tried to do was get the window title of the minecraft and categorize if its an error or the actual game.

This is what i did

Private Sub Timer3_Tick_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
Dim p As Process
For Each p In Process.GetProcessesByName("javaw")
TextBox2.Text = (p.MainWindowTitle.ToString)
Next
End Sub

Interval to 100 Enabled True

then

Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
If TextBox2.Text = "" Or TextBox2.Text = "Java Virtual Machine Launcher" Then
Timer4.Start()
Else
Timer4.Stop()
Timer2.Stop()
End If
End Sub

Interval to 1000 Activated by a button.

Then

Private Sub Timer3_Tick_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
Dim p As Process
For Each p In Process.GetProcessesByName("javaw")
TextBox2.Text = (p.MainWindowTitle.ToString)
Next
End Sub

Interval 100 Enabled true


So this transfers the window title of the launched program to a textbox then the "if statement" compares it and if its the error, it kills the error and relaunch the program.

This is already a working program but i want to make the launching faster, the problem is if i
hasten the interval of timer 2, it sometimes kill the non, error program that successfully launched.

If anyone can help me, Hide the error or remove it please do help me. Im not yet an expert on vb.net but i want to learn from the best.
 
Generally speaking, if you want to run a game using Process.Start, you can't just pass the file name as an argument. Most games need their current working directory to be set to the folder containing their EXE, while your code will use the same current working directory as for your own app. You need to create a ProcessStartInfo and set at least the file path and the working directory, with the working directory being the same path as the folder containing the executable file. You then pass that ProcessStartInfo object as an argument when you call Process.Start.
 
My program works like this, the user clicks a command button, then it opens a openfiledialog which allows them to browse the main file needed which is a .exe.
After that the location gets copied into a textbox and i use it as the directory with the exe name already. i already tried the process startinfo and set the directory to the textbox.text.

I already made it open the program but the program (Almost) always makes an error and opens it up by chance. All i want is either get rid of the error or hide the error from opening and only show the program if its the actual game.

Here is my whole code.

Public Class Form1
Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
TextBox1.Text = OpenFileDialog1.FileName
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
OpenFileDialog1.ShowDialog()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Timer4.Stop()
Dim po As New Process
Dim launch As New ProcessStartInfo
launch.FileName = TextBox1.Text
launch.Arguments = "java -Xms1g -jar"
Process.Start(launch)
Timer2.Start()
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If TextBox1.Text = "Minecraft.exe Directory" Then
Button2.Enabled = False
Else
Button2.Enabled = True
End If
End Sub

Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim directory As String
My.Computer.Audio.Play(My.Resources.austinpowers, AudioPlayMode.Background)
directory = My.Computer.Registry.CurrentUser.OpenSubKey("Software\\Minecraft\\Launcher\\Config", True).GetValue("Directory")
If directory <> "" Then
TextBox1.Text = directory
End If
End Sub

Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
If TextBox2.Text = "" Or TextBox2.Text = "Java Virtual Machine Launcher" Then
Timer4.Start()
Else
Timer4.Stop()
Timer2.Stop()
End If
End Sub

Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)

End Sub

Private Sub Timer3_Tick_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
Dim p As Process
For Each p In Process.GetProcessesByName("javaw")
TextBox2.Text = (p.MainWindowTitle.ToString)
Next
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim answer As String
answer = MsgBox("Thankyou for using Minecraft Launcher, Would you like to save your settings?", vbYesNo + vbInformation, "Thankyou")
If answer = vbYes Then
My.Computer.Registry.SetValue("HKEY_CURRENT_USER\Software\Minecraft\Launcher\Config", "Directory", valueKind:=Microsoft.Win32.RegistryValueKind.String, value:=TextBox1.Text)
MsgBox("Settings saved in Registry", vbOKOnly + vbInformation, "Congratulations")
ElseIf answer = vbNo Then
Me.Show()
End
End If
End Sub

Private Sub Timer4_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer4.Tick
Dim pProcess() As Process = System.Diagnostics.Process.GetProcessesByName("javaw")
For Each p As Process In pProcess
p.WaitForInputIdle(2000)
p.Kill()
Next
Button2.PerformClick()
End Sub

Private Sub Timer5_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)

End Sub
End Class
 
Please do not, under any circumstances, post the same question more than once. I have deleted your other thread on this same topic.

You ignored the most important part of my reply:
You need to create a ProcessStartInfo and set at least the file path and the working directory, with the working directory being the same path as the folder containing the executable file.
Where are you setting the working directory?
 
the directory is not set by the program but by the user, i let the user browse for the file and the directory gets inputted in the textbox. Not i use that directory as the one to launch in the process.start

process.start(textbox1.text)

I am able to open the .exe but what i want to do is to actually block a certain process with a certain window title. Because i want to block the error with the name "Java Virtual Machine Launcher" name as it is an error and only pass and display the process if it is the main window of the game.
 
Back
Top