本文介绍了我怎样才能启动进程,隐藏的窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试过这样:

 的ProcessStartInfo PSI =新的ProcessStartInfo(http://stackoverflow.com/); 
psi.RedirectStandardOutput = FALSE;
psi.WindowStyle = ProcessWindowStyle.Hidden;
psi.UseShellExecute = FALSE;

的Process.Start(PSI);



但我发现上线的Process.Start(PSI)异常;



Win32Exception将系统找不到指定的文件



如果我更改线路psi.UseShellExecute = TRUE;
那么它的工作,但忽略了最低隐藏窗口



我想,当它打开broswer例如到的的用户将不会看到窗口在任何时间,但该窗口仍然被打开。这不是关闭而是隐藏它。



试过谷歌,但没有找到一个有效的解决方案。



该Win32Exception消息:

  System.ComponentModel.Win32Exception了未处理
HResult的= -2147467259
消息=的系统找不到指定
来源文件系统=
错误码= -2147467259
NativeErrorCode = 2
堆栈跟踪:在System.Diagnostics.Process.StartWithCreateProcess
(的ProcessStartInfo的StartInfo)
在System.Diagnostics.Process.Start()
在System.Diagnostics.Process.Start(的ProcessStartInfo的StartInfo)
在CuteDadyImages.Form1.OpenBroswerTab()在d:\C夏普\test\Form1.cs:\C-Sharp\test\Form1.cs:行55
在CuteDadyImages在CuteDadyImages.Form1..ctor()在D线155
。 Program.Main()在d:\C-Sharp\test\Program.cs:行35
在System.AppDomain._nExecuteAssembly(RuntimeAssembly组装,字串[] args)
的系统。 AppDomain.ExecuteAssembly(字符串assemblyFile,证据assemblySecurity,字串[] args)
在Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
在System.Threading.ThreadHelper.ThreadStart_Context(对象状态)
。在System.Threading.ExecutionContext.RunInternal(ExecutionContext中的ExecutionContext,ContextCallback回调,对象状态,布尔preserveSyncCtx)
在System.Threading.ExecutionContext.Run(ExecutionContext中的ExecutionContext,ContextCallback回调,对象状态,布尔preserveSyncCtx)
。在System.Threading.ExecutionContext.Run(ExecutionContext中的ExecutionContext,ContextCallback回调,对象状态)在System.Threading.ThreadHelper.ThreadStart
()
的InnerException:


解决方案

添加在你的代码下面的地方

 函数[DllImport(user32.dll中)] 
私人静态外部布尔的ShowWindow(IntPtr的的HWND,的Int32的nCmdShow);

和则尝试使用以下启动浏览器:

  VAR过程=新的Process 
{
的StartInfo =
{
的FileName =firefox.exe,
参数=http://stackoverflow.com/,
CreateNoWindow = TRUE,
ErrorDialog =假,
WindowStyle = ProcessWindowStyle.Hidden
}
};
的Process.Start();
Thread.sleep代码(1000);
的ShowWindow(process.MainWindowHandle,0);


I tried this:

ProcessStartInfo psi = new ProcessStartInfo("http://stackoverflow.com/");
            psi.RedirectStandardOutput = false;
            psi.WindowStyle = ProcessWindowStyle.Hidden;
            psi.UseShellExecute = false;

            Process.Start(psi);

But i'm getting exception on the line Process.Start(psi);

Win32Exception The system cannot find the file specified

If i change the line psi.UseShellExecute = true;Then it's working but it dosen't hide the window.

I want that when it's opening the broswer for example to http://stackoverflow.com/ the user will not see the window at any time but that the window will still be opened. It's not to close but hiding it.

Tried to google but didn't find a working solution.

The Win32Exception message:

System.ComponentModel.Win32Exception was unhandled
  HResult=-2147467259
  Message=The system cannot find the file specified
  Source=System
  ErrorCode=-2147467259
  NativeErrorCode=2
  StackTrace:
       at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
       at System.Diagnostics.Process.Start()
       at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
       at CuteDadyImages.Form1.OpenBroswerTab() in d:\C-Sharp\test\Form1.cs:line 155
       at CuteDadyImages.Form1..ctor() in d:\C-Sharp\test\Form1.cs:line 55
       at CuteDadyImages.Program.Main() in d:\C-Sharp\test\Program.cs:line 35
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException:
解决方案

Add the following somewhere in your code

[DllImport("user32.dll")]
private static extern Boolean ShowWindow(IntPtr hWnd, Int32 nCmdShow);

And then try starting the browser using the following:

        var process = new Process
        {
            StartInfo =
            {
                FileName = "firefox.exe",
                Arguments = "http://stackoverflow.com/",
                CreateNoWindow = true,
                ErrorDialog = false,
                WindowStyle = ProcessWindowStyle.Hidden
            }
        };
        process.Start();
        Thread.Sleep(1000);
        ShowWindow(process.MainWindowHandle, 0);

这篇关于我怎样才能启动进程,隐藏的窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 19:40