Skip to content

Commit

Permalink
弃用setx方式设置环境变量
Browse files Browse the repository at this point in the history
  • Loading branch information
indiff committed Mar 28, 2024
1 parent 9298cf2 commit 3e624d1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 36 deletions.
61 changes: 27 additions & 34 deletions SetHome/SetHomeForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 13 additions & 2 deletions SetHome/SetHomeForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
using System.Runtime.InteropServices;
using System.Threading;
using Microsoft.Win32;
using System.Windows.Shell;
using System.Text.RegularExpressions;
using System.Text;

namespace SetHome
{
Expand Down Expand Up @@ -112,6 +111,7 @@ public static string RemovePathEndBackslash(string origin)
/// <param name="isSysVar">是否是系统变量</param>
public static void RunSetx(string varName, string value, bool isSysVar)
{
/*
new Thread(() =>
{
List<string> args = new List<string>();
Expand All @@ -124,6 +124,17 @@ public static void RunSetx(string varName, string value, bool isSysVar)
args.Add(value);
RunCommand("setx", args.ToArray());
}).Start();
*/

List<string> args = new List<string>();
if (isSysVar)
{
args.Add("/m");
}
args.Add(varName);
// value = RemovePathEndBackslash(value);
args.Add(value);
RunCommand("setx", args.ToArray());
}

/// <summary>
Expand Down

0 comments on commit 3e624d1

Please sign in to comment.