Solved

DOS command in VB.NET

Posted on 2007-11-27
5
4,111 Views
Last Modified: 2012-08-13
Hello, I simply need to execute DOS command from VB.NET code.

This is the code that I run from DOS:

C:\Program Files\omniformat\omniformat.exe "C:\test\test.xls" "PDF"

So, how to execute this same command from VB.NET.

I assume it would use something in this format:
Dim pInfo As New ProcessStartInfo("command/filename", "arguments")
            Dim p As New Process()
            p.StartInfo = pInfo
            p.Start()

but I am not sure what is the correct syntax i.e. what should be my command/filename, and what goes under arguments.

Can someoneprovide me with the code that will work in my situation?
Thanks
0
Comment
Question by:Terrace
  • 2
  • 2
5 Comments
 
LVL 22

Expert Comment

by:RedKelvin
ID: 20362104
Hi,
You can do this with the shell function

http://www.developerfusion.co.uk/show/9/
0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 500 total points
ID: 20362133
Just do it as:
Dim args as String =  chr(34) & "C:\test\test.xls" & chr(34) & " " & chr(34) & "PDF" & chr(34)
System.Diagnostics.Process.Start("C:\Program Files\omniformat\omniformat.exe", args);
0
 
LVL 22

Expert Comment

by:RedKelvin
ID: 20362160
If you want to use processstartinfo, you can do this

Dim MyProcess as New Process
Dim psi as New ProcessStartInfo()
psi.FileName="C:\Program Files\omniformat\omniformat.exe"
psi.Arguments="C:\test\test.xls PDF"
MyProcess.ProcessStartInfo=psi
MyProcess.Start()
MyProcess.WaitForExit()

for strings with spaces in them you may need to double ", but not 100% sure.
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20362171
notice that the arguments have double quotes
0
 
LVL 3

Expert Comment

by:bnaveke
ID: 20365506
Dim strTemp as String
Dim iTemp As Integer

strTemp = "C:\Program Files\omniformat\omniformat.exe 'C:\test\test.xls' 'PDF'"
iTemp = Shell(strTemp, AppWinStyle.MinimizedNoFocus)


FYI,

ITemp will be the processid

Other Enumeration value Description
AppWinStyle.Hide
AppWinStyle.NormalFocus
AppWinStyle.MinimizedFocus
AppWinStyle.MaximizedFocus
AppWinStyle.NormalNoFocus  
AppWinStyle.MinimizedNoFocus
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question