Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

DOS command in VB.NET

Posted on 2007-11-27
5
Medium Priority
?
4,179 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 2000 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

926 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