using System; using System.Diagnostics; using System.IO; using System.Text; namespace HelloWorld { class Hello { static void Main(string[] args) { Execute("calc.exe"); } public static bool Execute(string command) { if (String.IsNullOrEmpty(command)) { return false; } string fullPath = command; ProcessStartInfo psi = new ProcessStartInfo(); psi.FileName = Path.GetFileName(fullPath); psi.WorkingDirectory = Path.GetDirectoryName(fullPath); string args = ""; if (fullPath[0] == '"') { int pos = fullPath.IndexOf("\"", 1); if (pos != -1) { psi.FileName = Path.GetFileName(fullPath.Substring(1, pos)); psi.WorkingDirectory = Path.GetDirectoryName(fullPath.Substring(1, pos)); if (pos + 2 < fullPath.Length && fullPath[pos + 2] == ' ') { args = fullPath.Substring(pos + 2); } } else { psi.FileName = Path.GetFileName(fullPath.Substring(1)); psi.WorkingDirectory = Path.GetDirectoryName(fullPath.Substring(1)); } } else if (fullPath.IndexOf(" ") == -1 && fullPath.IndexOf("\\\\") == -1) { Process.Start(fullPath); return true; } else { int pos = fullPath.IndexOf(" "); if (pos != -1) { psi.FileName = Path.GetFileName(fullPath.Substring(0, pos)); psi.WorkingDirectory = Path.GetDirectoryName(fullPath.Substring(0, pos)); if (pos + 1 < fullPath.Length) { args = fullPath.Substring(pos + 1); } } } psi.Arguments = args; Process.Start(psi); return true; } } }