Board index » Visual Studio » Shell Command Problem

Shell Command Problem

Visual Studio257
I apologize for starting another thread but the old one had a weird subject

line. Anyways...here is the code:



Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As

System.EventArgs) Handles Button1.Click



Dim strInput As String = Application.StartupPath &

"\CreateMameGamesCFG.bat"



If lblMameExePath.Text <>"" Then



Dim sr As StreamWriter = File.CreateText(strInput)



sr.WriteLine(lblMameExePath.Text & " -listinfo>""" &

Application.StartupPath & "\mamegames.cfg""")



sr.Close()



Dim response As String



response = MsgBox("You will be notified when the operation is

complete.", MsgBoxStyle.OKOnly, "CPViewer")



If File.Exists(strInput) Then



Shell(strInput, AppWinStyle.Hide, True)



response = MsgBox("Your file has been created

successfully.", MsgBoxStyle.OKOnly, "CPViewer")



Else



response = MsgBox("Your file has NOT been created.",

MsgBoxStyle.OKOnly, "CPViewer")



End If



Else



Dim response As String



response = MsgBox("You must first specify the path to your mame

executable", MsgBoxStyle.OKOnly, "CPViewer")



End If



End Sub





The variable strInput contains a path and file name. It gets created fine

using the streamwriter. the If File.Exists even evaluates to true and the

code enters the if statement. When it gets to the shell command it errors

out whith the following error:



An unhandled exception of type 'System.IO.FileNotFoundException' occurred in

microsoft.visualbasic.dll







Additional information: File not found.







How can this possible be. It's almost like its a bug with the Shell command.

It was working for a while. Well, upon further checking here is what I got.

It worked in the GDI. I created an install package. Installed the app and it

worked. I messed around a little (not sure what I did) in the GDI and now it

won't work while in the GDI. I created another install package, installed it

and it works great but still won't work inside the GDI. Any ideas here? I'm

lost.







Thank you,



John


-
 

Re:Shell Command Problem

Hi John,

Not a problem with the shell command being able to handle long file names?

Just a guess.

Bob

jcrouse wrote:



Quote
I apologize for starting another thread but the old one had a weird subject

line. Anyways...here is the code:



Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As

System.EventArgs) Handles Button1.Click



Dim strInput As String = Application.StartupPath &

"\CreateMameGamesCFG.bat"



If lblMameExePath.Text <>"" Then



Dim sr As StreamWriter = File.CreateText(strInput)



sr.WriteLine(lblMameExePath.Text & " -listinfo>""" &

Application.StartupPath & "\mamegames.cfg""")



sr.Close()



Dim response As String



response = MsgBox("You will be notified when the operation is

complete.", MsgBoxStyle.OKOnly, "CPViewer")



If File.Exists(strInput) Then



Shell(strInput, AppWinStyle.Hide, True)



response = MsgBox("Your file has been created

successfully.", MsgBoxStyle.OKOnly, "CPViewer")



Else



response = MsgBox("Your file has NOT been created.",

MsgBoxStyle.OKOnly, "CPViewer")



End If



Else



Dim response As String



response = MsgBox("You must first specify the path to your mame

executable", MsgBoxStyle.OKOnly, "CPViewer")



End If



End Sub





The variable strInput contains a path and file name. It gets created fine

using the streamwriter. the If File.Exists even evaluates to true and the

code enters the if statement. When it gets to the shell command it errors

out whith the following error:



An unhandled exception of type 'System.IO.FileNotFoundException' occurred in

microsoft.visualbasic.dll







Additional information: File not found.







How can this possible be. It's almost like its a bug with the Shell command.

It was working for a while. Well, upon further checking here is what I got.

It worked in the GDI. I created an install package. Installed the app and it

worked. I messed around a little (not sure what I did) in the GDI and now it

won't work while in the GDI. I created another install package, installed it

and it works great but still won't work inside the GDI. Any ideas here? I'm

lost.







Thank you,



John























--

Please take out the garbage before using reply address.



-

Re:Shell Command Problem

Hi John,



Did you already see what the process start can do for you?



Here 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 = False

p.StartInfo.RedirectStandardOutput = False

p.StartInfo.Arguments = "\?"

p.StartInfo.WorkingDirectory = "C:\mydir"

p.StartInfo.FileName = "myProg.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

























Quote
I apologize for starting another thread but the old one had a weird

subject

line. Anyways...here is the code:



Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As

System.EventArgs) Handles Button1.Click



Dim strInput As String = Application.StartupPath &

"\CreateMameGamesCFG.bat"



If lblMameExePath.Text <>"" Then



Dim sr As StreamWriter = File.CreateText(strInput)



sr.WriteLine(lblMameExePath.Text & " -listinfo>""" &

Application.StartupPath & "\mamegames.cfg""")



sr.Close()



Dim response As String



response = MsgBox("You will be notified when the operation is

complete.", MsgBoxStyle.OKOnly, "CPViewer")



If File.Exists(strInput) Then



Shell(strInput, AppWinStyle.Hide, True)



response = MsgBox("Your file has been created

successfully.", MsgBoxStyle.OKOnly, "CPViewer")



Else



response = MsgBox("Your file has NOT been created.",

MsgBoxStyle.OKOnly, "CPViewer")



End If



Else



Dim response As String



response = MsgBox("You must first specify the path to your

mame

executable", MsgBoxStyle.OKOnly, "CPViewer")



End If



End Sub





The variable strInput contains a path and file name. It gets created fine

using the streamwriter. the If File.Exists even evaluates to true and the

code enters the if statement. When it gets to the shell command it errors

out whith the following error:



An unhandled exception of type 'System.IO.FileNotFoundException' occurred

in

microsoft.visualbasic.dll







Additional information: File not found.







How can this possible be. It's almost like its a bug with the Shell

command.

It was working for a while. Well, upon further checking here is what I

got.

It worked in the GDI. I created an install package. Installed the app and

it

worked. I messed around a little (not sure what I did) in the GDI and now

it

won't work while in the GDI. I created another install package, installed

it

and it works great but still won't work inside the GDI. Any ideas here?

I'm

lost.







Thank you,



John























-