Hello! I am learning how to program on my own in visual basic. I have made a program where the user selects a batch file from a datagridview that is populated with information from the hard drive. I have been able to get the selected item to show up as text in textbox1 (this includes c:\, not just the filename). When the user presses a button, what ever is in the text box is run. However I receive errors during the launching process.

I am on Windows 7 running Vb Express Edition 2008 w/

Process.Start("c:\something.bat")

Gives an error: Can not be found

Also, once the above works, how would I go about doing this?

Process.Start("cmd.exe", TextBox1.Text)

Installed Stuff:

Microsoft Visual Studio 2008
Version 9.0.30729.1 SP
Microsoft .NET Framework
Version 3.5 SP1

Installed Edition: VB Express

Microsoft Visual Basic 2008   91908-152-0000043-60199
Microsoft Visual Basic 2008

Hotfix for Microsoft Visual Basic 2008 Express Edition with SP1 - ENU (KB945282)   KB945282
This hotfix is for Microsoft Visual Basic 2008 Express Edition with SP1 - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit [url]http://support.microsoft.com/kb/945282[/url].

Hotfix for Microsoft Visual Basic 2008 Express Edition with SP1 - ENU (KB946040)   KB946040
This hotfix is for Microsoft Visual Basic 2008 Express Edition with SP1 - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit [url]http://support.microsoft.com/kb/946040[/url].

Hotfix for Microsoft Visual Basic 2008 Express Edition with SP1 - ENU (KB946308)   KB946308
This hotfix is for Microsoft Visual Basic 2008 Express Edition with SP1 - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit [url]http://support.microsoft.com/kb/946308[/url].

Hotfix for Microsoft Visual Basic 2008 Express Edition with SP1 - ENU (KB946344)   KB946344
This hotfix is for Microsoft Visual Basic 2008 Express Edition with SP1 - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit [url]http://support.microsoft.com/kb/946344[/url].

Hotfix for Microsoft Visual Basic 2008 Express Edition with SP1 - ENU (KB947540)   KB947540
This hotfix is for Microsoft Visual Basic 2008 Express Edition with SP1 - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit [url]http://support.microsoft.com/kb/947540[/url].

Hotfix for Microsoft Visual Basic 2008 Express Edition with SP1 - ENU (KB947789)   KB947789
This hotfix is for Microsoft Visual Basic 2008 Express Edition with SP1 - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit [url]http://support.microsoft.com/kb/947789[/url].

Hotfix for Microsoft Visual Basic 2008 Express Edition with SP1 - ENU (KB948127)   KB948127
This hotfix is for Microsoft Visual Basic 2008 Express Edition with SP1 - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit [url]http://support.microsoft.com/kb/948127[/url].

Hotfix for Microsoft Visual Basic 2008 Express Edition with SP1 - ENU (KB951708)   KB951708
This hotfix is for Microsoft Visual Basic 2008 Express Edition with SP1 - ENU.
If you later install a more recent service pack, this hotfix will be uninstalled automatically.
For more information, visit [url]http://support.microsoft.com/kb/951708[/url].

Thank you!

Recommended Answers

All 4 Replies

to try and re-create your problem to find a solution.... i made a file and placed it in C:\ and made a new form in VB and when i pressed the button on the form it would Process.start("C:\lol.bat") and it worked perfect.... the only way i could create a "file cant be found, Error" is when the PATH was incorrect. EX: C:\documents\lol.bat would produce an error. so make sure your file IS in C:\

ALSO

i am running windows 7 VB.net 2008 just like you are

When working with Files, you should always check if the File exists.

Dim myCoolFile As String = "c:\something.bat" '// your file.

        If IO.File.Exists(myCoolFile) Then '// check if File exists.
            Process.Start(myCoolFile)
        Else '// if File does not exist...
            MsgBox("File Does Not Exist.", MsgBoxStyle.Critical) '// display message.
        End If

As for "cmd.exe", see if this helps.

I have not been able to try out your addition, but I am wondering how I would go about changing the c:\something to a user supplied variable.

Dim myCoolFile As String = "c:\something.bat"

I might be confused because of my c++ knowledge. If you are to replace a string supplied to a function that normally is supplied with a string in quotes with a variable, you must do all sorts of extra steps (strcmp(), check if the array is long enough).

See if this helps.

Public Class Form1
    Private myCoolFile As String = "c:\some old.bat" '// original string.
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        myCoolFile = "c:\something.bat" '// new string.
        MsgBox(myCoolFile) '// display string.
        End
    End Sub
End Class
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.