Running the dos command

laxman

Freshman
Joined
Jun 14, 2008
Messages
28
Dear ALL,

I am developing the windows application which interacts with one external hardware, with this hardware i have to run a command which perofrms an operation with the hardware. this i am running in the DOS, But actually this should run in back ground(Pageload) mean while i have to show another screen, i am able get run the command but whenever it is running the dos screen is showing and closing i want to avoid showing the dos screen how i can do this
 
Not sure exactly what you mean, windows no longer runs ontop of dos, but you can still execute commandline programs.

Try this:

System.Diagnostics.Process.Start("yourCommandLine.exe /arg /arg /arg");

As for talking to hardware running dos, I'd need more information to give you advice.
 
If you truely want to run the DOS app in the background while the page is loading, try using a BackgroundWorker Thread.

Using an anonymous method:
Code:
using (BackgroundWorker worker = new BackgroundWorker()) {
  worker.DoWork += delegate {
    System.Diagnostics.Process.Start("yourCommandLine.exe /arg /arg /arg");
  };
  worker.RunWorkerCompleted += delegate {
    // do whatever you need to do with the values returned from the
    // command line exe.
    Cursor = Cursors.Default;
  };
  worker.RunWorkerAsync();
  if (worker.IsBusy == true) {
  Cursor = Cursors.AppStarting;
  }
}
 
This should do the trick:

Code:
        Dim ExeString As String = "netsh.exe"
        Dim ArgumentString As String = "interface ip set address ""Local Area Connection"" static 192.168.0.83 255.255.255.0"

        Dim DosCommand As Process = New Process
        DosCommand.StartInfo.CreateNoWindow = True
        DosCommand.StartInfo.UseShellExecute = False
        DosCommand.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
        DosCommand.StartInfo.FileName = ExeString
        DosCommand.StartInfo.Arguments = ArgumentString
        DosCommand.Start()


You can use the following to check if the DOS program has ended:
Code:
        DosCommand.HasExited
 
Back
Top