2012-07-13 86 views
0

我正在使用来自服务的类库运行应用程序的EXE。 但是我试图做的是隐藏应用程序EXE的窗口。 这里是我的代码:如何隐藏应用程序窗口,当它的EXE从进程调用?

在我的类库的功能: -

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(); 
    } 
} 

而且这是在那里我从调用它:

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

尽管上述所有的,窗口尚未见到。 任何人都可以请建议一个解决方案?

感谢和问候, Siddhant

+0

奇怪,这不应该发生。也;是否为您开启或关闭服务与桌面设置进行交互?检查您的服务属性 – 2012-07-13 10:58:02

+0

其实我认为我会修改我的问题多一点.. – Siddhant 2012-07-13 11:13:28

+1

可能(C# - 启动隐形进程[CreateNoWindow和WindowStyle不工作?)](http://stackoverflow.com/questions/3011209/ c-sharp-launch -invisible-process-createnowindow-windowstyle-not-working)帮助 – Arne 2012-07-13 11:16:30

回答

0

我曾尝试你的代码不工作,但

但是,当我这样尝试一下它工作正常

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

Process.Start(startInfo); 

原因,它的工作原理与Process.Start(ProcessStartInfo),因为它 将给定的信息与新组件关联,如 MSDN

0

我已经得到了答案的家伙,这要归功于this评论,这是我从Arne的评论得到了在这个问题的顶部..显然,这似乎Process.StartInfo.UseShellExecute应该设置为true

感谢大家的帮助!干杯!

0
string filePath = @"C:\Windows\System32\notepad.exe"; 
ProcessStartInfo pStartInfo = new ProcessStartInfo(filePath); 

**pStartInfo.UseShellExecute = true;** 

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

注:设置pStartInfo.UseShellExecutetrue否则,你得到一个错误

相关问题