Skip to content

Commit 3e624d1

Browse files
committed
弃用setx方式设置环境变量
1 parent 9298cf2 commit 3e624d1

File tree

2 files changed

+40
-36
lines changed

2 files changed

+40
-36
lines changed

SetHome/SetHomeForm.Designer.cs

+27-34
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

SetHome/SetHomeForm.cs

+13-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
using System.Runtime.InteropServices;
1111
using System.Threading;
1212
using Microsoft.Win32;
13-
using System.Windows.Shell;
14-
using System.Text.RegularExpressions;
13+
using System.Text;
1514

1615
namespace SetHome
1716
{
@@ -112,6 +111,7 @@ public static string RemovePathEndBackslash(string origin)
112111
/// <param name="isSysVar">是否是系统变量</param>
113112
public static void RunSetx(string varName, string value, bool isSysVar)
114113
{
114+
/*
115115
new Thread(() =>
116116
{
117117
List<string> args = new List<string>();
@@ -124,6 +124,17 @@ public static void RunSetx(string varName, string value, bool isSysVar)
124124
args.Add(value);
125125
RunCommand("setx", args.ToArray());
126126
}).Start();
127+
*/
128+
129+
List<string> args = new List<string>();
130+
if (isSysVar)
131+
{
132+
args.Add("/m");
133+
}
134+
args.Add(varName);
135+
// value = RemovePathEndBackslash(value);
136+
args.Add(value);
137+
RunCommand("setx", args.ToArray());
127138
}
128139

129140
/// <summary>

0 commit comments

Comments
 (0)