954,517 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Process.Start(variable)

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 <a href="http://support.microsoft.com/kb/945282">http://support.microsoft.com/kb/945282</a> .

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 <a href="http://support.microsoft.com/kb/946040">http://support.microsoft.com/kb/946040</a> .

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 <a href="http://support.microsoft.com/kb/946308">http://support.microsoft.com/kb/946308</a> .

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 <a href="http://support.microsoft.com/kb/946344">http://support.microsoft.com/kb/946344</a> .

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 <a href="http://support.microsoft.com/kb/947540">http://support.microsoft.com/kb/947540</a> .

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 <a href="http://support.microsoft.com/kb/947789">http://support.microsoft.com/kb/947789</a> .

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 <a href="http://support.microsoft.com/kb/948127">http://support.microsoft.com/kb/948127</a> .

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 <a href="http://support.microsoft.com/kb/951708">http://support.microsoft.com/kb/951708</a> .

Thank you!

cr6564
Newbie Poster
3 posts since Nov 2010
Reputation Points: 10
Solved Threads: 0
 

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

eikal
Light Poster
35 posts since Jan 2010
Reputation Points: 10
Solved Threads: 2
 

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.

codeorder
Posting Virtuoso
1,913 posts since Aug 2010
Reputation Points: 255
Solved Threads: 384
 

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).

cr6564
Newbie Poster
3 posts since Nov 2010
Reputation Points: 10
Solved Threads: 0
 

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
codeorder
Posting Virtuoso
1,913 posts since Aug 2010
Reputation Points: 255
Solved Threads: 384
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: