【发布时间】:2015-05-23 14:58:07
【问题描述】:
我试过了:
ProcessStartInfo psi = new ProcessStartInfo("https://stackoverflow.com/");
psi.RedirectStandardOutput = false;
psi.WindowStyle = ProcessWindowStyle.Hidden;
psi.UseShellExecute = false;
Process.Start(psi);
但我在 Process.Start(psi); 线上遇到了异常
Win32Exception 系统找不到指定的文件
如果我更改行 psi.UseShellExecute = true; 然后它就可以工作了,但它并没有隐藏窗口。
我希望当它打开浏览器时,例如https://stackoverflow.com/,用户在任何时候都不会看到窗口,但窗口仍然会打开。不是关闭而是隐藏。
尝试谷歌但没有找到有效的解决方案。
Win32Exception 消息:
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:
【问题讨论】:
-
"http://stackoverflow.com/"不是可执行文件的有效路径。如果要打开 URL,则必须在此处指定浏览器可执行文件。但是隐藏浏览器并没有多大意义…… -
见this。