Execute a .JAR file from VB. [Solved]

Posts 1–15 of 15 · Page 1 of 1
Execute a .JAR file from VB. [Solved]
So i'm currently working on a minecraft Server GUI and i ran in to this little problem.

I dont know how i can open a .Jar applet file inside the visual basic.
or it could also be cool if i could open a batch/console In my GUI.

I don't mean that i want to decompile it i just want so the text that are being written once you open the .jar or the bach file are being also written in my GUI but without acctualy opening the file it self just trough the GUI.

Hope i Explained it well...

Didn understand nothing...

Ex: You want to read the .jar content and put in a textbox? or what?
Quote Originally Posted by Lyoto Machida View Post
Didn understand nothing...

Ex: You want to read the .jar content and put in a textbox? or what?
Well kind of but not the codes inside the file but once the jar is runned it opens a batch where it you can see ath the server is starting up and all that text and i want to open the program so it's kind of a batch file that is inside the visual basic program

It's Alittle bit hard to explain

Ill Upload pics just in a minute ;D to show what i want help with



This is what i mean
Hope u guys can help me


You want the text that is in the cmd window?
So here: ( I dont have time to explain it..)
Import the System.Text
Code:
       
            Dim Processo As New Process
            Dim ProcInfo As New ProcessStartInfo(YOUR PROCESS, PROCESS ATRIBUTES )
            Processo.StartInfo = ProcInfo
            ProcInfo.UseShellExecute = False
            ProcInfo.RedirectStandardError = True
            ProcInfo.RedirectStandardInput = True
            ProcInfo.RedirectStandardOutput = True
            Processo.Start()

            Dim CMDString As New StringBuilder

            Dim ReadingCMDString As IO.StreamReader = Processo.StandardOutput

            While Not ReadingCMDString.EndOfStream
                Dim Line As String = ReadingCMDString.ReadLine
                Try
                    If Not Line = vbNullString Then
                        CMDString.AppendLine(Trim(Line))
                    End If

                Catch ex As Exception

                End Try


            End While
            ReadingCMDString.Close()

            Processo.WaitForExit(1)

            TextBox1.Text = CMDString.ToString
        Catch ex As Exception

        End Try
Thanks

Too Short


Got a new Problem when i have this code in and i start thr program and and i click the button to open the cmd it start's the cmd it self i dont need it to star only type in the text that the cmd is typing. and once it acctualy is open nothing happens in the cmd.? this is my code
Code:
 Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
        TextBox3.Text = OpenFileDialog1.FileName
        Dim Processo As New Process
        Dim ProcInfo As New ProcessStartInfo(TextBox3.Text)
        Processo.StartInfo = ProcInfo
        ProcInfo.UseShellExecute = False
        ProcInfo.RedirectStandardError = True
        ProcInfo.RedirectStandardInput = True
        ProcInfo.RedirectStandardOutput = True
        Processo.Start()
        Dim CMDString As New StringBuilder

        Dim ReadingCMDString As IO.StreamReader = Processo.StandardOutput

        While Not ReadingCMDString.EndOfStream
            Dim Line As String = ReadingCMDString.ReadLine
            Try
                If Not Line = vbNullString Then
                    CMDString.AppendLine(Trim(Line))
                End If

            Catch ex As Exception

            End Try


        End While
        ReadingCMDString.Close()

        Processo.WaitForExit(1)
        Try
            TextBox1.Text = CMDString.ToString
        Catch ex As Exception
        End Try
    End Sub
Quote Originally Posted by danishfps View Post
Thanks

Too Short


Got a new Problem when i have this code in and i start thr program and and i click the button to open the cmd it start's the cmd it self i dont need it to star only type in the text that the cmd is typing. and once it acctualy is open nothing happens in the cmd.? this is my code
Code:
 Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
        TextBox3.Text = OpenFileDialog1.FileName
        Dim Processo As New Process
        Dim ProcInfo As New ProcessStartInfo(TextBox3.Text)
        Processo.StartInfo = ProcInfo
        ProcInfo.UseShellExecute = False
        ProcInfo.RedirectStandardError = True
        ProcInfo.RedirectStandardInput = True
        ProcInfo.RedirectStandardOutput = True
        Processo.Start()
        Dim CMDString As New StringBuilder

        Dim ReadingCMDString As IO.StreamReader = Processo.StandardOutput

        While Not ReadingCMDString.EndOfStream
            Dim Line As String = ReadingCMDString.ReadLine
            Try
                If Not Line = vbNullString Then
                    CMDString.AppendLine(Trim(Line))
                End If

            Catch ex As Exception

            End Try


        End While
        ReadingCMDString.Close()

        Processo.WaitForExit(1)
        Try
            TextBox1.Text = CMDString.ToString
        Catch ex As Exception
        End Try
    End Sub
You want it in real time? The code? Idk how to do that..Wait for the pros..
Read the stdout of the process which you can start via. System.Diagnostics.Process.Start, and passing it a StartInfo that specifies for the StandardOutput to be redirected to your app (which you can read via. a SteamReader).

Lol spam.
Quote Originally Posted by freedompeace View Post
Read the stdout of the process which you can start via. System.Diagnostics.Process.Start, and passing it a StartInfo that specifies for the StandardOutput to be redirected to your app (which you can read via. a SteamReader).

Lol spam.
Hmmmmmmm......

Well i Understand NOTHING could you make an example?
Try the following if you just want to have the window in your own program:

[highlight="VB.NET"]Imports System****ntime.InteropServices
Imports System.IO

Public Class Form1

#Region "DLLImports"

<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function ShowWindow(ByVal hWnd As IntPtr, ByVal nCmdShow As Integer) As Boolean
End Function

<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function SetParent(ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As IntPtr
End Function

<DllImport("user32.dll")> _
Private Shared Function SetWindowLong(ByVal hWnd As IntPtr, ByVal nIndex As Short, ByVal dwNewLong As Integer) As Integer
End Function

<DllImport("user32.dll")> _
Private Shared Function GetWindowLong(ByVal hWnd As IntPtr, ByVal nIndex As Integer) As Integer
End Function

Const SW_MAXIMIZE As Integer = 3
Const GWL_STYLE As Integer = -16

#End Region

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
WindowToPanel("C:\Dokumente und Einstellungen\Xerxes\Desktop\random.bat", Panel1)
End Sub

Dim pProcess As New System.Diagnostics.Process

Private Sub WindowToPanel(ByVal Filepath As String, ByVal Panel As Panel)
Panel.Visible = False
Try
pProcess.StartInfo.FileName = Filepath
pProcess.StartInfo.WorkingDirectory = Path.GetDirectoryName(Filepath)
pProcess.StartInfo.WindowStyle = ProcessWindowStyle.Minimized
pProcess.Start()

SetParent(pProcess.MainWindowHandle, Panel.Handle)
ShowWindow(pProcess.MainWindowHandle, SW_MAXIMIZE)

Dim frm As Integer = GetWindowLong(pProcess.MainWindowHandle, GWL_STYLE)
SetWindowLong(pProcess.MainWindowHandle, GWL_STYLE, frm And Not 12582912)

Panel.Visible = True
Catch ex As Exception
MessageBox.Show(ex.Message.ToString(), "Info")
End Try

Panel1.Visible = True
End Sub
[/highlight]

If you need to know what's in the cmd window listen to the guys below.

Quote Originally Posted by Blubb1337 View Post
Try the following if you just want to have the window in your own program:

[highlight="VB.NET"]Imports System****ntime.InteropServices
Imports System.IO

Public Class Form1

#Region "DLLImports"

<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function ShowWindow(ByVal hWnd As IntPtr, ByVal nCmdShow As Integer) As Boolean
End Function

<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function SetParent(ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As IntPtr
End Function

<DllImport("user32.dll")> _
Private Shared Function SetWindowLong(ByVal hWnd As IntPtr, ByVal nIndex As Short, ByVal dwNewLong As Integer) As Integer
End Function

<DllImport("user32.dll")> _
Private Shared Function GetWindowLong(ByVal hWnd As IntPtr, ByVal nIndex As Integer) As Integer
End Function

Const SW_MAXIMIZE As Integer = 3
Const GWL_STYLE As Integer = -16

#End Region

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
WindowToPanel("C:\Dokumente und Einstellungen\Xerxes\Desktop\random.bat", Panel1)
End Sub

Dim pProcess As New System.Diagnostics.Process

Private Sub WindowToPanel(ByVal Filepath As String, ByVal Panel As Panel)
Panel.Visible = False
Try
pProcess.StartInfo.FileName = Filepath
pProcess.StartInfo.WorkingDirectory = Path.GetDirectoryName(Filepath)
pProcess.StartInfo.WindowStyle = ProcessWindowStyle.Minimized
pProcess.Start()

SetParent(pProcess.MainWindowHandle, Panel.Handle)
ShowWindow(pProcess.MainWindowHandle, SW_MAXIMIZE)

Dim frm As Integer = GetWindowLong(pProcess.MainWindowHandle, GWL_STYLE)
SetWindowLong(pProcess.MainWindowHandle, GWL_STYLE, frm And Not 12582912)

Panel.Visible = True
Catch ex As Exception
MessageBox.Show(ex.Message.ToString(), "Info")
End Try

Panel1.Visible = True
End Sub
[/highlight]

If you need to know what's in the cmd window listen to the guys below.


IDK how you did it. The code is not getting me any errors but once i run the program it just opens the cmd in a new window not inside my application this is my code.
Code:
Imports System****ntime.InteropServices
Imports System.IO
Public Class Form1
#Region "DLLImports"

    <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
    Private Shared Function ShowWindow(ByVal hWnd As IntPtr, ByVal nCmdShow As Integer) As Boolean
    End Function

    <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
    Private Shared Function SetParent(ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As IntPtr
    End Function

    <DllImport("user32.dll")> _
    Private Shared Function SetWindowLong(ByVal hWnd As IntPtr, ByVal nIndex As Short, ByVal dwNewLong As Integer) As Integer
    End Function

    <DllImport("user32.dll")> _
    Private Shared Function GetWindowLong(ByVal hWnd As IntPtr, ByVal nIndex As Integer) As Integer
    End Function

    Const SW_MAXIMIZE As Integer = 3
    Const GWL_STYLE As Integer = -16

#End Region

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
    Dim pProcess As New System.Diagnostics.Process

    Private Sub WindowToPanel(ByVal Filepath As String, ByVal Panel As Panel)
        Panel.Visible = False
        Try
            pProcess.StartInfo.FileName = Filepath
            pProcess.StartInfo.WorkingDirectory = Path.GetDirectoryName(Filepath)
            pProcess.StartInfo.WindowStyle = ProcessWindowStyle.Minimized
            pProcess.Start()

            SetParent(pProcess.MainWindowHandle, Panel.Handle)
            ShowWindow(pProcess.MainWindowHandle, SW_MAXIMIZE)

            Dim frm As Integer = GetWindowLong(pProcess.MainWindowHandle, GWL_STYLE)
            SetWindowLong(pProcess.MainWindowHandle, GWL_STYLE, frm And Not 12582912)

            Panel.Visible = True
        Catch ex As Exception
            MessageBox.Show(ex.Message.ToString(), "Info")
        End Try

        Panel1.Visible = True
    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 OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
        TextBox1.Text = OpenFileDialog1.FileName
        WindowToPanel(TextBox1.Text, Panel1)
    End Sub
End Class
Quote Originally Posted by Blubb1337 View Post
Try the following if you just want to have the window in your own program:

[highlight="VB.NET"]Imports System****ntime.InteropServices
Imports System.IO

Public Class Form1

#Region "DLLImports"

<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function ShowWindow(ByVal hWnd As IntPtr, ByVal nCmdShow As Integer) As Boolean
End Function

<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function SetParent(ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As IntPtr
End Function

<DllImport("user32.dll")> _
Private Shared Function SetWindowLong(ByVal hWnd As IntPtr, ByVal nIndex As Short, ByVal dwNewLong As Integer) As Integer
End Function

<DllImport("user32.dll")> _
Private Shared Function GetWindowLong(ByVal hWnd As IntPtr, ByVal nIndex As Integer) As Integer
End Function

Const SW_MAXIMIZE As Integer = 3
Const GWL_STYLE As Integer = -16

#End Region

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
WindowToPanel("C:\Dokumente und Einstellungen\Xerxes\Desktop\random.bat", Panel1)
End Sub

Dim pProcess As New System.Diagnostics.Process

Private Sub WindowToPanel(ByVal Filepath As String, ByVal Panel As Panel)
Panel.Visible = False
Try
pProcess.StartInfo.FileName = Filepath
pProcess.StartInfo.WorkingDirectory = Path.GetDirectoryName(Filepath)
pProcess.StartInfo.WindowStyle = ProcessWindowStyle.Minimized
pProcess.Start()

SetParent(pProcess.MainWindowHandle, Panel.Handle)
ShowWindow(pProcess.MainWindowHandle, SW_MAXIMIZE)

Dim frm As Integer = GetWindowLong(pProcess.MainWindowHandle, GWL_STYLE)
SetWindowLong(pProcess.MainWindowHandle, GWL_STYLE, frm And Not 12582912)

Panel.Visible = True
Catch ex As Exception
MessageBox.Show(ex.Message.ToString(), "Info")
End Try

Panel1.Visible = True
End Sub
[/highlight]

If you need to know what's in the cmd window listen to the guys below.

CMD in a program? i would use that.
but dosnt he want the cmd text to only be there not the whole thing?
Quote Originally Posted by Cal View Post

CMD in a program? i would use that.
but dosnt he want the cmd text to only be there not the whole thing?
Well, Ya. That's what i wanted but apparently i can't get help with that.
Quote Originally Posted by danishfps View Post
Well, Ya. That's what i wanted but apparently i can't get help with that.
You did get help with that...you just chose to ignore it because it wasn't a direct spoonfeed.

As simple as can be:

[highlight=vb.net]
Private Function readProcessOutput(ByVal filePath As String) As String
Dim retVal As String = String.Empty
Dim proc As New Process With {.StartInfo = New ProcessStartInfo With {.FileName = filePath, .RedirectStandardOutput = True, .UseShellExecute = False}}
proc.Start()
Using sRead As IO.StreamReader = proc.StandardOutput
retVal = sRead.ReadToEnd
End Using
proc.WaitForExit(0)
Return retVal
End Function
[/highlight]

All you need to do is plug in the location of the process, and then assign the result to a textbox:

[highlight=vb.net]
TextBox1.Text = readProcessOutput(Environment.GetFolderPath(Enviro nment.SpecialFolder.Desktop) & "\test.bat")
[/highlight]

Doesn't come any simpler than that.
Quote Originally Posted by Jason View Post


You did get help with that...you just chose to ignore it because it wasn't a direct spoonfeed.

As simple as can be:

[highlight=vb.net]
Private Function readProcessOutput(ByVal filePath As String) As String
Dim retVal As String = String.Empty
Dim proc As New Process With {.StartInfo = New ProcessStartInfo With {.FileName = filePath, .RedirectStandardOutput = True, .UseShellExecute = False}}
proc.Start()
Using sRead As IO.StreamReader = proc.StandardOutput
retVal = sRead.ReadToEnd
End Using
proc.WaitForExit(0)
Return retVal
End Function
[/highlight]

All you need to do is plug in the location of the process, and then assign the result to a textbox:

[highlight=vb.net]
TextBox1.Text = readProcessOutput(Environment.GetFolderPath(Enviro nment.SpecialFolder.Desktop) & "\test.bat")
[/highlight]

Doesn't come any simpler than that.
Thank You alot

Could you just help men once again
Code:
TextBox1.Text = readProcessOutput(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\test.bat")
what if i want to open the batch file froms some other folder then desktop.
Can i instead of typinf desktop or some other specialfolder type in textbox2.text?
Quote Originally Posted by danishfps View Post
Thank You alot

Could you just help men once again
Code:
TextBox1.Text = readProcessOutput(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\test.bat")
what if i want to open the batch file froms some other folder then desktop.
Can i instead of typinf desktop or some other specialfolder type in textbox2.text?
You only need to use the Environment.GetFolderPath for paths like ApplicationData, Desktop etc..

You can just put in a regular file location:

[highlight=vb.net]
TextBox1.Text = readProcessOutput("C\Users\Jason\Documents\test.ba t")
[/highlight]
Posts 1–15 of 15 · Page 1 of 1

Post a Reply

Tags for this Thread

None

Talk with us