Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 391
  • Last Modified:

Start another application as a process

I want to run another application (a legacy application) as a process from my .NET Windows Application, and I want to hide the window of legacy application, I don't want it show up, how to do that?  I can't even hide a notepad or calculator, Notepad or Calculator still pop up, what am I missing?

private void button1_Click(object sender, System.EventArgs e)
{
Process myProcess = new Process();
try
{
myProcess.StartInfo.WindowStyle= ProcessWindowStyle.Hidden;
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.CreateNoWindow = true;
myProcess.StartInfo.RedirectStandardOutput = true;
myProcess.StartInfo.FileName =@"C:\\WINDOWS\\system32\\notepad.exe";
myProcess.Start();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
      
0
ToneElec
Asked:
ToneElec
  • 3
  • 3
  • 2
1 Solution
 
eguilhermeCommented:
have you tried setting


myProcess.StartInfo.CreateNoWindow = true;

to false


myProcess.StartInfo.CreateNoWindow = false;
0
 
eguilhermeCommented:
 you can also try to set the WindowStyle = ProcessWindowStyle.Hidden;
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
To use the Hidden style, first set UseShellExecute() to TRUE:
private void button1_Click(object sender, System.EventArgs e)
        {
            Process myProcess = new Process();
            try
            {
                myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                myProcess.StartInfo.UseShellExecute = true;
                myProcess.StartInfo.FileName = "notepad.exe";
                myProcess.Start();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }

Open in new window

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ToneElecAuthor Commented:
Thank you for your reply.  Setting UseShellExecute() to TRUE make it work.  
0
 
ToneElecAuthor Commented:
This is something I don't understand, yesterday I set UseShellExecute() to TRUE, just as Idle_Mind mentioned, it worked and it hide the process window, no matter notepad, calculator or my program.  However, today it only hide notepad, not calculator, or my program.  What's going on?
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
It's possible you have a bug in your program and it's not compiling...and you are running a version that is not current?

Otherwise show us your current code...
0
 
ToneElecAuthor Commented:
Idle_Mind:

I made my executable program (VC++ 6.0) dialog box disabled, so it will run as a process, doesn't pop up the window.  Your program can successfully hide Notepad, for some  reason, it doesn't hide Calculator.  Is there a difference between those two?   I am using Microsoft Visual Studio 2003.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Not sure why some windows don't like being hidden...sorry.

Can you give the "big picture" of your project?  Maybe there is another approach that would work.
0

Featured Post

Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

  • 3
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now