Solved

DOS command in VB.NET

Posted on 2007-11-27
5
4,156 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
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 …
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

630 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