Solved

DOS command in VB.NET

Posted on 2007-11-27
5
4,065 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
notice that the arguments have double quotes
0
 
LVL 3

Expert Comment

by:bnaveke
Comment Utility
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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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.…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

728 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now