[VB.NET] trying to make a server starter

keroberos

Dedicated Member
Dedicated Member
Jan 1, 2007
11
0
47
I've been trying to make a server starter but when I push the start button i get alot of erros:






Heres my code:

Code:
Public Class Form1

    Dim OnDir As String

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim myProcesses() As Process
        Dim myProcess As Process
        myProcesses = Process.GetProcessesByName("Dbserver")
        For Each myProcess In myProcesses
            myProcess.Kill()
        Next
    End Sub

    Private Sub OFD_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OFD.FileOk
        If OnDir = "DBServer" Then
            ButtonEdit1.Text = OFD.FileName
            My.Settings.DBServer = OFD.FileName
            My.Settings.Save()
        ElseIf OnDir = "LoginGate" Then
            ButtonEdit2.Text = OFD.FileName
            My.Settings.LoginGate = OFD.FileName
            My.Settings.Save()
        ElseIf OnDir = "LoginServer" Then
            ButtonEdit3.Text = OFD.FileName
            My.Settings.LoginServer = OFD.FileName
            My.Settings.Save()
        ElseIf OnDir = "LogServer" Then
            ButtonEdit4.Text = OFD.FileName
            My.Settings.LogServer = OFD.FileName
            My.Settings.Save()
        ElseIf OnDir = "M2Server" Then
            ButtonEdit5.Text = OFD.FileName
            My.Settings.M2Server = OFD.FileName
            My.Settings.Save()
        ElseIf OnDir = "RunGate" Then
            ButtonEdit6.Text = OFD.FileName
            My.Settings.RunGate = OFD.FileName
            My.Settings.Save()
        ElseIf OnDir = "SelGate" Then
            ButtonEdit7.Text = OFD.FileName
            My.Settings.SelGate = OFD.FileName
            My.Settings.Save()
        End If
    End Sub

    Private Sub ButtonEdit1_ButtonClick(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.Controls.ButtonPressedEventArgs) Handles ButtonEdit1.ButtonClick
        OnDir = "DBServer"
        OFD.ShowDialog()
    End Sub

    Private Sub ButtonEdit2_ButtonClick(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.Controls.ButtonPressedEventArgs) Handles ButtonEdit2.ButtonClick
        OnDir = "LoginGate"
        OFD.ShowDialog()
    End Sub

    Private Sub ButtonEdit3_ButtonClick(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.Controls.ButtonPressedEventArgs) Handles ButtonEdit3.ButtonClick
        OnDir = "LoginServer"
        OFD.ShowDialog()
    End Sub

    Private Sub ButtonEdit4_ButtonClick(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.Controls.ButtonPressedEventArgs) Handles ButtonEdit4.ButtonClick
        OnDir = "LogServer"
        OFD.ShowDialog()
    End Sub

    Private Sub ButtonEdit5_ButtonClick(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.Controls.ButtonPressedEventArgs) Handles ButtonEdit5.ButtonClick
        OnDir = "M2Server"
        OFD.ShowDialog()
    End Sub

    Private Sub ButtonEdit6_ButtonClick(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.Controls.ButtonPressedEventArgs) Handles ButtonEdit6.ButtonClick
        OnDir = "RunGate"
        OFD.ShowDialog()
    End Sub

    Private Sub ButtonEdit7_ButtonClick(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.Controls.ButtonPressedEventArgs) Handles ButtonEdit7.ButtonClick
        OnDir = "SelGate"
        OFD.ShowDialog()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If ButtonEdit1.Text <> "" And ButtonEdit1.Text.EndsWith(".exe") Then
            If ButtonEdit2.Text <> "" And ButtonEdit2.Text.EndsWith(".exe") Then
                If ButtonEdit3.Text <> "" And ButtonEdit3.Text.EndsWith(".exe") Then
                    If ButtonEdit4.Text <> "" And ButtonEdit4.Text.EndsWith(".exe") Then
                        If ButtonEdit5.Text <> "" And ButtonEdit5.Text.EndsWith(".exe") Then
                            If ButtonEdit6.Text <> "" And ButtonEdit6.Text.EndsWith(".exe") Then
                                If ButtonEdit7.Text <> "" And ButtonEdit7.Text.EndsWith(".exe") Then
                                    Process.Start(ButtonEdit1.Text) 'DBServer
                                    Process.Start(ButtonEdit2.Text) 'LoginGate
                                    Process.Start(ButtonEdit3.Text) 'LoginServer
                                    Process.Start(ButtonEdit4.Text) 'LogServer

                                    Process.Start(ButtonEdit6.Text) 'RunGate
                                    Process.Start(ButtonEdit7.Text) 'SelectCharacterGate
                                    '-------------------------------
                                    Process.Start(ButtonEdit5.Text) 'M2Server
                                Else
                                    MsgBox(My.Resources.Error1, , "Error Code: 1")
                                End If
                            Else
                                MsgBox(My.Resources.Error1, , "Error Code: 1")
                            End If
                        Else
                            MsgBox(My.Resources.Error1, , "Error Code: 1")
                        End If
                    Else
                        MsgBox(My.Resources.Error1, , "Error Code: 1")
                    End If
                Else
                    MsgBox(My.Resources.Error1, , "Error Code: 1")
                End If
            Else
                MsgBox(My.Resources.Error1, , "Error Code: 1")
            End If
        Else
            MsgBox(My.Resources.Error1, , "Error Code: 1")
        End If
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If My.Settings.DBServer <> "" Then
            ButtonEdit1.Text = My.Settings.DBServer
        End If

        If My.Settings.LoginGate <> "" Then
            ButtonEdit2.Text = My.Settings.LoginGate
        End If

        If My.Settings.LoginServer <> "" Then
            ButtonEdit3.Text = My.Settings.LoginServer
        End If

        If My.Settings.LogServer <> "" Then
            ButtonEdit4.Text = My.Settings.LogServer
        End If

        If My.Settings.M2Server <> "" Then
            ButtonEdit5.Text = My.Settings.M2Server
        End If

        If My.Settings.RunGate <> "" Then
            ButtonEdit6.Text = My.Settings.RunGate
        End If

        If My.Settings.SelGate <> "" Then
            ButtonEdit7.Text = My.Settings.SelGate
        End If
    End Sub
End Class

The code I use for running the programme is:

Code:
Process.Start(ButtonEdit1.Text)
 

kyndigs

LOMCN Developer
Developer
Feb 19, 2009
1,126
117
190
Reading, UK
I dont really approve of that monolithic code for button1_click but whatever.

Anyway... the problem is you are creating an instance of that exe from your debug folder which is why its looking for the server files there. If you placed the exe in your M2 folder it would not throw any errors.

You could always try the Shell command.

Code:
  Dim err As Variant
  err = Shell(ButtonEdit1.Text, vbNormalFocus)
 

keroberos

Dedicated Member
Dedicated Member
Jan 1, 2007
11
0
47
I dont really approve of that monolithic code for button1_click but whatever.

Anyway... the problem is you are creating an instance of that exe from your debug folder which is why its looking for the server files there. If you placed the exe in your M2 folder it would not throw any errors.

You could always try the Shell command.

Code:
  Dim err As Variant
  err = Shell(ButtonEdit1.Text, vbNormalFocus)

Thanks for your help but that did not work :(

Also I could of done that code better, I'll work on that until I figure out the running of the programmes :P
 

Chriz

Captain Lurker
VIP
Mar 24, 2003
1,158
277
335
LOMCN
Have a look into the ShellExecute API, that allows you to set the default working directory, Thats what i used in my starter, good luck! ;)

Edit::

Heres an example

Dim Proc As New Process
With Proc
.StartInfo.UseShellExecute = True
.StartInfo.WorkingDirectory = "D:\Mir\mirserver\M2Server"
.StartInfo.FileName = "M2Server.exe"
.Start()
End With
 
Last edited:

kyndigs

LOMCN Developer
Developer
Feb 19, 2009
1,126
117
190
Reading, UK
Try setting the working directoy of the exe's.

Code:
        Dim processinfo As System.Diagnostics.ProcessStartInfo
        Dim process As New System.Diagnostics.Process

        processinfo = New System.Diagnostics.ProcessStartInfo(TextBox1.Text)
        processinfo.WorkingDirectory = "C:\MirServer\M2Server"
        process.StartInfo = processinfo
        process.Start()

You can just do a trim on the text boxes to remove the filename.exe bit.

Edit woops beat me to it :p
 

keroberos

Dedicated Member
Dedicated Member
Jan 1, 2007
11
0
47
unfortunelty neither of the above worked =[ thanks anyways guys
 

Hazuki

VIP
VIP
Apr 14, 2004
3,459
38
285
United Kingdom
A Shell command is the way to go :). I made a server starter many years ago, I may still have the code somewhere I will have to have a look.
 

mazz

Dedicated Member
Dedicated Member
Aug 6, 2008
193
2
65
Ive had this problem also try making a batch file that launches the server then use vb to launch the batch with the shell command



EVILD