CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2001
    Posts
    430

    close dos window by program

    every 30 seconds my app starts a console program which causes dos window opened. I want to close the dos window by my app before opening the new one. Please tell me how to do it. thanks.

    by the way, is it possible to get a list of the files to be installed (including running dlls) after the setup program made?

  2. #2
    Join Date
    Sep 1999
    Location
    Madurai , TamilNadu , INDIA
    Posts
    1,024

    Re: close dos window by program

    Process.Start() will return a Process object which contains information about the process that is started by this method. Store the reference in an instance variable. you can attach an Exit event handler to the returned process object. When the eventhandler is called, set the process reference to null.

    So, next time before you start another process, check the instance variable. If it is not null, call Kill() method on the Process object. It will terminate the existing one.

    Another option is, when you start a new dos command, you could use "/c" keyword. When your console program exits, the command prompt will be automatically closed.

    Process.Start("cmd.exe", "/c <yourconsoleapp>.exe");

  3. #3
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    1,080

    Re: close dos window by program

    If you just pass the name of a console app to Process.Start then the console window will close automatically when the app completes. If the app is not completing of its own accord then Process.Kill is the way to go, although you may want to think about whether you can change the console app to exit itself if that's possible. Also, you can use the ProcessStartInfo.CreateNoWindow property to prevent the console window being displayed.
    Tutorials: Home & Learn | Start VB.NET | Learn VB.NET | C# Station | GotDotNet | Games in VB.NET 101 Samples: 2002 | 2003 | 2005 | More .NET 2.0 (VB.NET, C#) Articles: VB.NET | C# | ASP.NET | MoreFree Components: WFC | XPCC | ElementsEx | VBPP | Mentalis | ADO.NET/MySQL | VisualStyles | Charting (NPlot, ZedGraph) | iTextSharp (PDF) | SDF (CF) ● Free Literature: VB 2005 (eBook) | VB6 to VB.NET (eBook) | MSDN Magazine (CHM format) ● Bookmarks: MSDN | WinForms .NET | ASP.NET | WinForms FAQ | WebForms FAQ | GotDotNet | Code Project | DevBuzz (CF) ● Code Converter: C#/VB.NET | VB.NET/C# | VS 2005 add-in

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured