static void Main(string[] args) { string theArguments; if (args.Length < 1) { MessageBox.Show(Properties.Resources.NO_ARGUMENTS, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "Shortcut Files|*.lnk"; ofd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.SendTo); if (ofd.ShowDialog() != DialogResult.OK) { return; } theArguments = AmbLib.getAllArgs(1); if (string.IsNullOrEmpty(theArguments)) { MessageBox.Show(Properties.Resources.NO_ARGUMENTS, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.FileName = ofd.FileName; startInfo.Arguments = theArguments; startInfo.UseShellExecute = true; startInfo.Verb = "runas"; startInfo.Arguments = theArguments; startInfo.WorkingDirectory = System.IO.Directory.GetParent(AmbLib.unDoubleQuote(AmbLib.getAllArgs(theArguments, 0, true))).FullName; try { Process proc = Process.Start(startInfo); // proc.WaitForExit(); } catch (Exception ex) { MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } //Application.EnableVisualStyles(); //Application.SetCompatibleTextRenderingDefault(false); //Application.Run(new FormMain()); }
static void Main(string[] args) { string theArguments; if (args.Length < 1) { MessageBox.Show(Properties.Resources.NO_ARGUMENTS, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (args[0] == "/run") { if (args.Length < 2) { MessageBox.Show(string.Format(Properties.Resources.NO_ARGUMENTS_AFTER_RUN), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } theArguments = AmbLib.getAllArgs(2); ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.FileName = AmbLib.getAllArgs(theArguments, 0, true); startInfo.Arguments = AmbLib.getAllArgs(theArguments, 1); startInfo.UseShellExecute = true; startInfo.Verb = "open"; //startInfo.Arguments = "start \"\" \"" + theFileName + "\""; //startInfo.Arguments = theFileName; try { Process proc = Process.Start(startInfo); // proc.WaitForExit(); } catch (Exception ex) { MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } return; } else // not with /run { theArguments = AmbLib.getAllArgs(1); ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.FileName = Application.ExecutablePath; startInfo.UseShellExecute = true; startInfo.Verb = IsAdmin() ? null : "runas"; startInfo.Arguments = "/run " + theArguments; startInfo.WorkingDirectory = System.IO.Directory.GetParent(AmbLib.unDoubleQuote(AmbLib.getAllArgs(theArguments, 0, true))).FullName;; try { Process proc = Process.Start(startInfo); // proc.WaitForExit(); } catch (Exception ex) { MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } return; } }