Browse Source

remove duplicate startup entries

fixes #3011

Signed-off-by: ahmadali shafiee <mail@ahmadalli.net>
tags/4.3.2.0
ahmadali shafiee 4 years ago
parent
commit
344c95e52c
1 changed files with 12 additions and 1 deletions
  1. +12
    -1
      shadowsocks-csharp/Controller/System/AutoStartup.cs

+ 12
- 1
shadowsocks-csharp/Controller/System/AutoStartup.cs View File

@@ -14,7 +14,7 @@ namespace Shadowsocks.Controller
// Don't use Application.ExecutablePath
// see https://stackoverflow.com/questions/12945805/odd-c-sharp-path-issue
private static string Key = "Shadowsocks_" + Program.ExecutablePath.GetHashCode();
public static bool Set(bool enabled)
@@ -28,6 +28,17 @@ namespace Shadowsocks.Controller
logger.Error(@"Cannot find HKCU\Software\Microsoft\Windows\CurrentVersion\Run");
return false;
}
// Remove other startup keys with the same executable path. fixes #3011
foreach (var valueName in runKey.GetValueNames())
{
if (valueName == Key)
continue;
if (string.Equals(runKey.GetValue(valueName).ToString(), Program.ExecutablePath, StringComparison.InvariantCultureIgnoreCase))
{
runKey.DeleteValue(valueName);
}
}
if (enabled)
{
runKey.SetValue(Key, Program.ExecutablePath);


Loading…
Cancel
Save