You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
3.0 KiB

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)
Console.WriteLine("usage: LocalExplorer.exe <path to open with Explorer.exe>");
WriteOutputFile("no args passed to program");
//Collect up the path
//the replace function is here to trim out the arg as it
//comes in from the url protocol handler
string path = args[0].Replace("localexplorer:", "").Replace("%5C", "\\");
//If there is a space in the path as it comes from the URL
//protocol handler, replace it with an actual space.
path = path.Replace("%20", " ");
WriteOutputFile($"arg passed: {path}");
//Check to see if the directory exists.
//if so, pop it open.
if (Directory.Exists(path))
ProcessStartInfo startInfo = new ProcessStartInfo
Arguments = path,
FileName = "explorer.exe"
//put this inside try/catch block just in case
//explorer.exe has a permission issue or something.
Console.WriteLine($"Could not proc explorer.exe to open {path}");
WriteOutputFile($"Could not proc explorer.exe to open {path}");
WriteOutputFile($"Directory does not exist: {path}");
Console.WriteLine("Directory does not exist.");
} //end main
private static void WriteOutputFile(string debugLine)
// comment this out to debug the program
StreamWriter outFile = new StreamWriter(@"C:\LocalExplorer\OUTPUT.txt", true);