0

I'm running an application's EXE using a Class Library from a Service. But what i'm attempting to do is hide the application EXE's Window. Here is my code:

In my Class Library's function:-

public class MyClassLibrary
{
    public void MyFunction()
    {
        Process process = new Process();
        process.StartInfo.FileName = "C:\Program Files (x86)\MyFolder\MyApp.exe";
        process.StartInfo.CreateNoWindow = true;
        process.StartInfo.UseShellExecute = false;
        process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
        process.Start();
    }
}

And this is where i'm calling it from:

class MyClass : ServiceBase
{
    ...
    ...
    ...
    protected override void OnStart()
    {
        MyClassLibrary obj = new MyClassLibrary();
        obj.MyFunction();
    }
}

Despite all of the above, the window is yet seen. Can anyone please suggest a solution?

Thanks and Regards, Siddhant

Siddhant
  • 1,074
  • 12
  • 22

3 Answers3

0

I have tried your code in does not work but

But when i try it this way it works fine

string filePath = @"C:\Program Files (x86)\Internet Explorer\iexplore.exe";    
ProcessStartInfo pStartInfo = new ProcessStartInfo(filePath );
pStartInfo.WindowStyle = ProcessWindowStyle.Hidden;

Process.Start(startInfo);

Reason it works with Process.Start(ProcessStartInfo) because it associates the given information with a new component as explained on MSDN

HatSoft
  • 11,077
  • 3
  • 28
  • 43
0

I've got the answer guys, thanks to this comment, which i got from Arne's comment at the top of this question.. Apparently it seems that the Process.StartInfo.UseShellExecute was supposed to be set to true.

Thanks everyone for helping out! Cheers!

Community
  • 1
  • 1
Siddhant
  • 1,074
  • 12
  • 22
0
string filePath = @"C:\Windows\System32\notepad.exe";
ProcessStartInfo pStartInfo = new ProcessStartInfo(filePath);

**pStartInfo.UseShellExecute = true;** 

pStartInfo.WindowStyle = ProcessWindowStyle.Hidden;   
Process.Start(pStartInfo);

Note: Set pStartInfo.UseShellExecute to true otherwise you get an error

Smittey
  • 2,475
  • 10
  • 28
  • 35
gupta123
  • 11
  • 2