How to run an exe using VB.NET

  • Thread starter K.NagaKiranKumar
  • Start date
K

K.NagaKiranKumar

Hi

I have stucked up on a problem....
I am developing an application in VB.NET
Here I have to put a button on a form
and by clicking on that button, an exe should run.

see the code I am using...

------------------
Private Sub btnstartgalciv_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
btnstartgalciv.Click
Dim path As String
path = "C:\galciv\galciv.exe"
If path <> "" And mFSO.FileExists(path) Then
System.Diagnostics.Process.Start(path)
'Shell(path & "\galciv.exe",
AppWinStyle.MaximizedFocus, True, 10000)
Else
MsgBox("Galactic Civilizations is not
installed", MsgBoxStyle.Information, "Information")
End If
End Sub
------------------

In above code I have tried in both ways

1)System.Diagnostics.Process.Start(path)
2)'Shell(path & "\galciv.exe", AppWinStyle.MaximizedFocus,
True, 10000)

and also triesd to assign system.diagnosti....... to a
variable.

The problem I am facing is.....
When I click the button, The exe is starting it's
execution and immidiately terminanting its process.

Here I am trying to invoke a game by clicking a
button,placed on the form.

Plz.......reply


thanks, bye
 
C

Cor Ligthert

Hi Some samples.
\\\
Dim p As New System.Diagnostics.ProcessStartInfo()
p.Verb = "print"
p.WindowStyle = ProcessWindowStyle.Hidden
p.FileName = "C:\filename.doc"
p.UseShellExecute = True
System.Diagnostics.Process.Start(p)
///
Dim p As New Process
p.StartInfo.UseShellExecute = True
p.StartInfo.Arguments = "c:\windows\win.ini"
p.StartInfo.FileName = "notepad.exe"
p.Start()
///
\\\
Dim p As New Process
p.StartInfo.UseShellExecute = False
p.StartInfo.RedirectStandardOutput = True
p.StartInfo.Arguments = myargumentstring
p.StartInfo.WorkingDirectory = myworkdirectorystring
p.StartInfo.FileName =C:\myprogram
p.Start()
Dim sr As IO.StreamReader = p.StandardOutput
Dim sb As New System.Text.StringBuilder("")
Dim input As Integer = sr.Read
Do Until input = -1
sb.Append(ChrW(input))
input = sr.Read
Loop
///
I hope this helps a little bit?

Cor
 
O

One Handed Man \( OHM - Terry Burns \)

It's probably something to do with the environment the games needs, like
paths etc

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing
 
H

Herfried K. Wagner [MVP]

* "K.NagaKiranKumar said:
Here I have to put a button on a form
and by clicking on that button, an exe should run.

see the code I am using...

------------------
Private Sub btnstartgalciv_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
btnstartgalciv.Click
Dim path As String
path = "C:\galciv\galciv.exe"
If path <> "" And mFSO.FileExists(path) Then

Use 'Path.Length > 0' to check if a string's length is > 0. In this
case, that's not even necessary because you check if the file exists.
There is a managed way to check if a file exists,
'System.IO.File.Exists'.
System.Diagnostics.Process.Start(path)

Should basically work.
'Shell(path & "\galciv.exe",
AppWinStyle.MaximizedFocus, True, 10000)


I suggest to use 'Path.Combine' to combine the path with the filename.
When I click the button, The exe is starting it's
execution and immidiately terminanting its process.

Have a look at the 'ProcessStartInfo' class. Maybe the application
requires a working directory to be set.
 

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