Solved

DOS command in VB.NET

Posted on 2007-11-27
5
4,100 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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

778 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