diff --git a/Program.cs b/Program.cs index 0b8eea3..1cbb7bb 100644 --- a/Program.cs +++ b/Program.cs @@ -1,17 +1,28 @@ /* - * REFERENCE: + * REFERENCES: * https://www.joe0.com/2019/01/27/how-create-a-custom-browser-uri-scheme-and-c-protocol-handler-client-that-supports-opening-and-editing-of-remotely-hosted-documents-through-webdav/ + * https://stackoverflow.com/questions/44675085/minimize-console-at-app-startup-c-sharp + * */ using System; using System.Diagnostics; using System.IO; +using System.Runtime.InteropServices; namespace LocalExplorer { class Program { + [DllImport("User32.dll", CallingConvention = CallingConvention.StdCall, SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + private static extern bool ShowWindow([In] IntPtr hWnd, [In] int nCmdShow); + static void Main(string[] args) { + //Start this process hidden + IntPtr handle = Process.GetCurrentProcess().MainWindowHandle; + ShowWindow(handle, 0); + //Check to make sure a path was passed in as an argument to the program. if (args.Length == 0) { @@ -37,7 +48,17 @@ namespace LocalExplorer FileName = "explorer.exe" }; - Process.Start(startInfo); + //put this inside try/catch block just in case + //explorer.exe has a permission issue or something. + try + { + Process.Start(startInfo); + } + catch + { + Console.WriteLine($"Could not proc explorer.exe to open {path}"); + WriteOutputFile($"Could not proc explorer.exe to open {path}"); + } } else { @@ -48,8 +69,8 @@ namespace LocalExplorer private static void WriteOutputFile(string debugLine) { - return; - // remove the above return for debugging + // comment this out to debug the program + //return; StreamWriter outFile = new StreamWriter(@"C:\LocalExplorer\OUTPUT.txt", true); outFile.WriteLine(debugLine);