18
18
using System . Collections . Generic ;
19
19
using System . Linq ;
20
20
using System . Management . Automation ;
21
- using Chocolatey . PowerShell . Shared ;
22
21
using Chocolatey . PowerShell . Win32 ;
23
22
using Microsoft . Win32 ;
23
+ using static chocolatey . StringResources ;
24
24
25
25
namespace Chocolatey . PowerShell . Helpers
26
26
{
@@ -163,7 +163,7 @@ public static void SetVariable(PSCmdlet cmdlet, string name, EnvironmentVariable
163
163
// The value doesn't exist yet, suppress the error.
164
164
}
165
165
166
- if ( name . ToUpper ( ) == EnvironmentVariables . Path )
166
+ if ( name . ToUpper ( ) == EnvironmentVariables . System . Path )
167
167
{
168
168
registryType = RegistryValueKind . ExpandString ;
169
169
}
@@ -199,8 +199,8 @@ public static void SetVariable(PSCmdlet cmdlet, string name, EnvironmentVariable
199
199
out UIntPtr result ) ;
200
200
201
201
// 2. Set a user environment variable making the system refresh
202
- var setxPath = string . Format ( @"{0}\System32\setx.exe" , GetVariable ( cmdlet , EnvironmentVariables . SystemRoot , EnvironmentVariableTarget . Process ) ) ;
203
- cmdlet . InvokeCommand . InvokeScript ( $ "& \" { setxPath } \" { EnvironmentVariables . ChocolateyLastPathUpdate } \" { DateTime . Now . ToFileTime ( ) } \" ") ;
202
+ var setxPath = string . Format ( @"{0}\System32\setx.exe" , GetVariable ( cmdlet , EnvironmentVariables . System . SystemRoot , EnvironmentVariableTarget . Process ) ) ;
203
+ cmdlet . InvokeCommand . InvokeScript ( $ "& \" { setxPath } \" { EnvironmentVariables . Package . ChocolateyLastPathUpdate } \" { DateTime . Now . ToFileTime ( ) } \" ") ;
204
204
}
205
205
}
206
206
catch ( Exception error )
@@ -217,16 +217,16 @@ public static void SetVariable(PSCmdlet cmdlet, string name, EnvironmentVariable
217
217
/// <param name="cmdlet">The cmdlet calling the method.</param>
218
218
public static void UpdateSession ( PSCmdlet cmdlet )
219
219
{
220
- var userName = GetVariable ( cmdlet , EnvironmentVariables . Username , EnvironmentVariableTarget . Process ) ;
221
- var architecture = GetVariable ( cmdlet , EnvironmentVariables . ProcessorArchitecture , EnvironmentVariableTarget . Process ) ;
222
- var psModulePath = GetVariable ( cmdlet , EnvironmentVariables . PSModulePath , EnvironmentVariableTarget . Process ) ;
220
+ var userName = GetVariable ( cmdlet , EnvironmentVariables . System . Username , EnvironmentVariableTarget . Process ) ;
221
+ var architecture = GetVariable ( cmdlet , EnvironmentVariables . System . ProcessorArchitecture , EnvironmentVariableTarget . Process ) ;
222
+ var psModulePath = GetVariable ( cmdlet , EnvironmentVariables . System . PSModulePath , EnvironmentVariableTarget . Process ) ;
223
223
224
224
var scopeList = new List < EnvironmentVariableTarget > ( ) { EnvironmentVariableTarget . Process , EnvironmentVariableTarget . Machine } ;
225
225
226
- var computerName = GetVariable ( cmdlet , EnvironmentVariables . ComputerName , EnvironmentVariableTarget . Process ) ;
226
+ var computerName = GetVariable ( cmdlet , EnvironmentVariables . System . ComputerName , EnvironmentVariableTarget . Process ) ;
227
227
228
228
// User scope should override (be checked after) machine scope, but only if we're not running as SYSTEM
229
- if ( userName != computerName && userName != EnvironmentVariables . System )
229
+ if ( userName != computerName && userName != EnvironmentVariables . System . SystemName )
230
230
{
231
231
scopeList . Add ( EnvironmentVariableTarget . User ) ;
232
232
}
@@ -247,23 +247,23 @@ public static void UpdateSession(PSCmdlet cmdlet)
247
247
248
248
// Update PATH, combining both scopes' values.
249
249
var paths = new string [ 2 ] ;
250
- paths [ 0 ] = GetVariable ( cmdlet , EnvironmentVariables . Path , EnvironmentVariableTarget . Machine ) ;
251
- paths [ 1 ] = GetVariable ( cmdlet , EnvironmentVariables . Path , EnvironmentVariableTarget . User ) ;
250
+ paths [ 0 ] = GetVariable ( cmdlet , EnvironmentVariables . System . Path , EnvironmentVariableTarget . Machine ) ;
251
+ paths [ 1 ] = GetVariable ( cmdlet , EnvironmentVariables . System . Path , EnvironmentVariableTarget . User ) ;
252
252
253
- SetVariable ( cmdlet , EnvironmentVariables . Path , EnvironmentVariableTarget . Process , string . Join ( ";" , paths ) ) ;
253
+ SetVariable ( cmdlet , EnvironmentVariables . System . Path , EnvironmentVariableTarget . Process , string . Join ( ";" , paths ) ) ;
254
254
255
255
// Preserve PSModulePath as it's almost always updated by process, preserve it
256
- SetVariable ( cmdlet , EnvironmentVariables . PSModulePath , EnvironmentVariableTarget . Process , psModulePath ) ;
256
+ SetVariable ( cmdlet , EnvironmentVariables . System . PSModulePath , EnvironmentVariableTarget . Process , psModulePath ) ;
257
257
258
258
// Preserve user and architecture
259
259
if ( ! string . IsNullOrEmpty ( userName ) )
260
260
{
261
- SetVariable ( cmdlet , EnvironmentVariables . Username , EnvironmentVariableTarget . Process , userName ) ;
261
+ SetVariable ( cmdlet , EnvironmentVariables . System . Username , EnvironmentVariableTarget . Process , userName ) ;
262
262
}
263
263
264
264
if ( ! string . IsNullOrEmpty ( architecture ) )
265
265
{
266
- SetVariable ( cmdlet , EnvironmentVariables . ProcessorArchitecture , EnvironmentVariableTarget . Process , architecture ) ;
266
+ SetVariable ( cmdlet , EnvironmentVariables . System . ProcessorArchitecture , EnvironmentVariableTarget . Process , architecture ) ;
267
267
}
268
268
}
269
269
}
0 commit comments