DotNetLogo

Start a new process hidden is really useful for some external calls to any other application around the system. For example, we can use it for making Registry backups using the REGEDIT.EXE giving the right arguments.

Here is the method to do it having support to exit code, arguments and wait for exit options to the new process.

        /*
 
         * StartProcessHidden C# method by Michel Oliveira.
         * 2013/05/14
         * www.joshcellsoftwares.com

         You may need to use these libraries on your project:
  
         System.Net;
  
         GPL License.
 
        */
        private static int StartProcessHidden(string FileName, bool WaitForExit, string Arguments = "")
        {
            using (Process myProc = new Process()) //Create a new object called myProc as Process.
            {
                myProc.StartInfo.FileName = FileName; //Give the process file name reveived by the method.
                myProc.StartInfo.Arguments = Arguments; //Give the arguments received.
                myProc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; //As hidden window style.
                myProc.StartInfo.CreateNoWindow = true; //Create no window property as true.
                myProc.StartInfo.UseShellExecute = false; //Disable the shellexecute since we do not want to see any window.
                myProc.Start(); //Start the process.
                if (WaitForExit)
                    myProc.WaitForExit(); //Wait for the process if the 'WaitForExit' was sent as true.
                return myProc.ExitCode; //Return the exit code of the process to the method.
            }
        }
'
' 
'         * StartProcessHidden VB.NET method by Michel Oliveira.
'         * 2013/05/14
'         * www.joshcellsoftwares.com
'
'         You may need to use these libraries on your project:
'  
'         System.Net;
'  
'         GPL License.
' 
'        

Private Shared Function StartProcessHidden(FileName As String, WaitForExit As Boolean, Optional Arguments As String = "") As Integer
	Using myProc As New Process()
		'Create a new object called myProc as Process.
		myProc.StartInfo.FileName = FileName
		'Give the process file name reveived by the method.
		myProc.StartInfo.Arguments = Arguments
		'Give the arguments received.
		myProc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
		'As hidden window style.
		myProc.StartInfo.CreateNoWindow = True
		'Create no window property as true.
		myProc.StartInfo.UseShellExecute = False
		'Disable the shellexecute since we do not want to see any window.
		myProc.Start()
		'Start the process.
		If WaitForExit Then
			myProc.WaitForExit()
		End If
		'Wait for the process if the 'WaitForExit' was sent as true.
			'Return the exit code of the process to the method.
		Return myProc.ExitCode
	End Using
End Function

Examples:

            StartProcessHidden("C:\\MyProcess.exe", false, "My Argument");
            StartProcessHidden("C:\MyProcess.exe", False, "My Argument")

Good Luck,

Michel Oliveira – Software Engineer and Startup founder at joshcellsoftwares.com.