diff --git a/shadowsocks-csharp/Controller/System/AutoStartup.cs b/shadowsocks-csharp/Controller/System/AutoStartup.cs index 8aa1f6d5..9f3e5ff2 100644 --- a/shadowsocks-csharp/Controller/System/AutoStartup.cs +++ b/shadowsocks-csharp/Controller/System/AutoStartup.cs @@ -1,4 +1,6 @@ using System; +using System.Collections.Generic; +using System.Linq; using System.Reflection; using System.Runtime.InteropServices; using System.Windows.Forms; @@ -127,11 +129,16 @@ namespace Shadowsocks.Controller // requested register and not autostartup if (register && !Check()) { + // escape command line parameter + string[] args = new List(Program.Args) + .Select(p => p.Replace("\"", "\\\"")) // escape " to \" + .Select(p => p.IndexOf(" ") >= 0 ? "\"" + p + "\"" : p) // encapsule with " + .ToArray(); + string cmdline = string.Join(" ", args); // first parameter is process command line parameter - // if ss-windows use it in future, remember pass it // needn't include the name of the executable in the command line - RegisterApplicationRestart(null, (int)ApplicationRestartFlags.RESTART_NO_CRASH | (int)ApplicationRestartFlags.RESTART_NO_HANG); - Logging.Debug("Register restart after system reboot"); + RegisterApplicationRestart(cmdline, (int)ApplicationRestartFlags.RESTART_NO_CRASH | (int)ApplicationRestartFlags.RESTART_NO_HANG); + Logging.Debug("Register restart after system reboot, command line:" + cmdline); } // requested unregister, which has no side effect else if (!register) diff --git a/shadowsocks-csharp/Program.cs b/shadowsocks-csharp/Program.cs index 8914ccef..a1763e38 100755 --- a/shadowsocks-csharp/Program.cs +++ b/shadowsocks-csharp/Program.cs @@ -16,13 +16,16 @@ namespace Shadowsocks { public static ShadowsocksController MainController { get; private set; } public static MenuViewController MenuController { get; private set; } - + public static string[] Args { get; private set; } /// /// 应用程序的主入口点。 /// + /// [STAThread] - static void Main() + static void Main(string[] args) { + // store args for further use + Args = args; // Check OS since we are using dual-mode socket if (!Utils.IsWinVistaOrHigher()) {