How to use VB Express to run a program through command promptinterface?


S

Sooraj

Hi,
I'm a mechanical engineer new to programming. I was trying to write a
program in Visual Basic Express Edition 2005. I want to run a file
using an application called madymo601 in command prompt.

Normally what I do is to go to Start> Run> and type cmd /k madymo601 c:
\filename.xml . I have put the /k there as i need the cmd window open
after execution to view the results. I tried to make a small VB
program to avoid typing in the commands since the .xml files I need to
run could be in various locations. I wrote a code as given below. But
seems to have something wrong with the diagnostics.process.start line.


Private Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
OpenFileDialog1.Title = "Please select .xml file"
OpenFileDialog1.Filter = "xml files|*.xml"
OpenFileDialog1.ShowDialog()
If OpenFileDialog1.FileName <> "" Then

TextBox1.Text = (OpenFileDialog1.FileName)
End If
End Sub

Private Sub Button2_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim filepath As String = (TextBox1.Text)

Diagnostics.Process.Start("cmd /k madymo601", filepath)
End Sub

Hope someone could help me out with the right way to do this.
Thanx.
 
Ad

Advertisements

K

kimiraikkonen

Hi,
I'm a mechanical engineer new to programming. I was trying to write a
program in Visual Basic Express Edition 2005. I want to run a file
using an application called madymo601 in command prompt.

Normally what I do is to go to Start> Run> and type cmd /k madymo601 c:
\filename.xml . I have put the /k there as i need the cmd window open
after execution to view the results. I tried to make a small VB
program to avoid typing in the commands since the .xml files I need to
run could be in various locations. I wrote a code as given below. But
seems to have something wrong with the diagnostics.process.start line.

Private Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
OpenFileDialog1.Title = "Please select .xml file"
OpenFileDialog1.Filter = "xml files|*.xml"
OpenFileDialog1.ShowDialog()
If OpenFileDialog1.FileName <> "" Then

TextBox1.Text = (OpenFileDialog1.FileName)
End If
End Sub

Private Sub Button2_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim filepath As String = (TextBox1.Text)

Diagnostics.Process.Start("cmd /k madymo601", filepath)
End Sub

Hope someone could help me out with the right way to do this.
Thanx.

Hi Sooraj,
To use Command prompt, you'd better use Shell instead of Process
class[Process class wants exact path of cmd.exe(c:\windows
\system32\cmd.exe..... unlike Shell)].

So, it would be like this:
Shell("cmd /k madymo601 filepath",AppWinStyle.NormalFocus)

And make sure you include exact path of your application to launch. I
mean, for example if you application (madymo601) resides as c:
\madymo601.exe then you should use:

Shell("cmd /k c:\madymo601 filepath",AppWinStyle.NormalFocus)

Hope this helps,

Onur Güzel
 
K

kimiraikkonen

Hi,
I'm a mechanical engineer new to programming. I was trying to write a
program in Visual Basic Express Edition 2005. I want to run a file
using an application called madymo601 in command prompt.
Normally what I do is to go to Start> Run> and type cmd /k madymo601 c:
\filename.xml . I have put the /k there as i need the cmd window open
after execution to view the results. I tried to make a small VB
program to avoid typing in the commands since the .xml files I need to
run could be in various locations. I wrote a code as given below. But
seems to have something wrong with the diagnostics.process.start line.
Private Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
OpenFileDialog1.Title = "Please select .xml file"
OpenFileDialog1.Filter = "xml files|*.xml"
OpenFileDialog1.ShowDialog()
If OpenFileDialog1.FileName <> "" Then
TextBox1.Text = (OpenFileDialog1.FileName)
End If
End Sub
Private Sub Button2_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim filepath As String = (TextBox1.Text)
Diagnostics.Process.Start("cmd /k madymo601", filepath)
End Sub
Hope someone could help me out with the right way to do this.
Thanx.

Hi Sooraj,
To use Command prompt, you'd better use Shell instead of Process
class[Process class wants exact path of cmd.exe(c:\windows
\system32\cmd.exe..... unlike Shell)].

So, it would be like this:
Shell("cmd /k madymo601 filepath",AppWinStyle.NormalFocus)

And make sure you include exact path of your application to launch. I
mean, for example if you application (madymo601) resides as c:
\madymo601.exe then you should use:

Shell("cmd /k c:\madymo601 filepath",AppWinStyle.NormalFocus)

Hope this helps,

Onur Güzel

Correcting my last post, you should use:(just added missing .exe
extension which you may not need)
Shell("cmd /k c:\madymo601.exe filepath",AppWinStyle.NormalFocus)

for the assumption above.

Onur
 
Ad

Advertisements

F

Family Tree Mike

Process takes a file to execute in the call you are using. You are passing
the entire command line, which is why it did not work.

If I were youI would do it as follows:

Dim p As New Process
p.StartInfo.FileName = "cmd"
p.StartInfo.Arguments = "/k madymo601 TheInputFile"
Process.Start
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top