How can I start a process and hide it?

I tried this:

ProcessStartInfo psi = new ProcessStartInfo("http://qaru.site/"); psi.RedirectStandardOutput = false; psi.WindowStyle = ProcessWindowStyle.Hidden; psi.UseShellExecute = false; Process.Start(psi); 

But I get an exception in the line Process.Start (psi);

Win32Exception System cannot find the specified file

If I change the line psi.UseShellExecute = true; Then it works, but does not close the window.

I want that when opening a browser, for example, /qaru.site / ... , the user will not see the window at any time, but the window will still be open. This is not to close, but to hide it.

I tried Google, but could not find a working solution.

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: 
+4
source share
2 answers

Add the following to your code:

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

And then try launching 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); 
+3
source

You can find all open forms from ApplicationOpenForms , and then you can hide them all, but there is one problem: this array is a list of only open forms and when one of them is closed or hidden, then this form is removed from the list and your For or loop Foreach goes to exception!

Check these codes to hide all open forms after you open your URL:

  Process.Start("http://stackoverflow.com/"); List<Form> oForms = new List<Form>(); foreach (Form form in Application.OpenForms) { oForms.Add(form); } foreach (var form in oForms) { form.Hide(); } 
-one
source

All Articles