tags:

views:

60

answers:

3

What function in VB.NET simply takes a string parameter and runs a command? It would work just like the OK button in the Start -> Run dialog.

Dim myCommand as String
myCommand = "excel C:\Documents and Settings\JohnDoe\Desktop\test.xls"
Run(myCommand)
+1  A: 

See the Shell method

Paulo Santos
Why is this better than System.Diagnostics.Process.Start(myCommand)?
Steven
+7  A: 

Try this:

System.Diagnostics.Process.Start(myCommand)
B Pete
Why is this better than Shell?
Steven
For your example, there's probably not much difference. Process.Start offers more features than shell. The Process.Start function can return a Process object. The Process object contains some info on the process (.ProcessName, for example) and also allows you to check to see if the project is still running and allows you to kill the process. There is also an overload that allows you to specify the command to run and the file to be opened as two seperate strings, which could simplify your program.
B Pete
+1  A: 

May be try next:

Dim excel As Microsoft.Office.Interop.Excel.Application
Dim wb As Microsoft.Office.Interop.Excel.Workbook
excel = New Microsoft.Office.Interop.Excel.Application
wb = excel.Workbooks.Open("C:\Documents and Settings\JohnDoe\Desktop\test.xls")
excel.Visible = True
wb.Activate()

It will open Excel and selected document

Anton
Do you recommend this over Shell/Start? If so, why?
Steven
If you want only open document Shell/Start is better way. But if you wanted to do something with file after opening, for example write something in document you cann't use Shell/Start.
Anton