Browse Source

set command line parameter when register restart, for future

tags/4.1.4
Student Main 5 years ago
parent
commit
447632ff07
2 changed files with 15 additions and 5 deletions
  1. +10
    -3
      shadowsocks-csharp/Controller/System/AutoStartup.cs
  2. +5
    -2
      shadowsocks-csharp/Program.cs

+ 10
- 3
shadowsocks-csharp/Controller/System/AutoStartup.cs View File

@@ -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<string>(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)


+ 5
- 2
shadowsocks-csharp/Program.cs View File

@@ -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; }
/// <summary>
/// 应用程序的主入口点。
/// </summary>
/// </summary>
[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())
{


Loading…
Cancel
Save