【问题标题】:How to hide Application Window when its EXE has been called from a Process?从进程调用其 EXE 时如何隐藏应用程序窗口?
【发布时间】:2012-07-13 10:54:04
【问题描述】:

我正在使用来自服务的类库运行应用程序的 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();
    }
}

尽管有上述所有情况,但仍然可以看到窗口。 有人可以提出解决方案吗?

感谢和问候, 悉达特

【问题讨论】:

  • 很奇怪,这不应该发生。还;您的服务的与桌面交互设置是打开还是关闭?检查您的服务属性
  • 其实我想我会修改我的问题多一点..
  • 可能是(C# - 启动不可见进程CreateNoWindow & WindowStyle not working?) 帮助
  • @GeraldVersluis - 我找不到那个设置..
  • @Arne - 我试过了,但没用.. 感谢您的帮助.. :)

标签: c# .net .net-services


【解决方案1】:

我试过你的代码不起作用,但是

但是当我尝试这种方式时,它工作正常

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

【讨论】:

    【解决方案2】:

    我得到了答案,感谢this 评论,我从这个问题顶部的Arne 的评论中得到了答案。显然,Process.StartInfo.UseShellExecute 应该设置为 true

    感谢大家的帮助!干杯!

    【讨论】:

      【解决方案3】:
      string filePath = @"C:\Windows\System32\notepad.exe";
      ProcessStartInfo pStartInfo = new ProcessStartInfo(filePath);
      
      **pStartInfo.UseShellExecute = true;** 
      
      pStartInfo.WindowStyle = ProcessWindowStyle.Hidden;   
      Process.Start(pStartInfo);
      

      注意:pStartInfo.UseShellExecute设置为true,否则会报错

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-09-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多