1818using System . Collections . Generic ;
1919using System . Linq ;
2020using System . Management . Automation ;
21- using Chocolatey . PowerShell . Shared ;
2221using Chocolatey . PowerShell . Win32 ;
2322using Microsoft . Win32 ;
23+ using static chocolatey . StringResources ;
2424
2525namespace Chocolatey . PowerShell . Helpers
2626{
@@ -163,7 +163,7 @@ public static void SetVariable(PSCmdlet cmdlet, string name, EnvironmentVariable
163163 // The value doesn't exist yet, suppress the error.
164164 }
165165
166- if ( name . ToUpper ( ) == EnvironmentVariables . Path )
166+ if ( name . ToUpper ( ) == EnvironmentVariables . System . Path )
167167 {
168168 registryType = RegistryValueKind . ExpandString ;
169169 }
@@ -199,8 +199,8 @@ public static void SetVariable(PSCmdlet cmdlet, string name, EnvironmentVariable
199199 out UIntPtr result ) ;
200200
201201 // 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 ( ) } \" ") ;
204204 }
205205 }
206206 catch ( Exception error )
@@ -217,16 +217,16 @@ public static void SetVariable(PSCmdlet cmdlet, string name, EnvironmentVariable
217217 /// <param name="cmdlet">The cmdlet calling the method.</param>
218218 public static void UpdateSession ( PSCmdlet cmdlet )
219219 {
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 ) ;
223223
224224 var scopeList = new List < EnvironmentVariableTarget > ( ) { EnvironmentVariableTarget . Process , EnvironmentVariableTarget . Machine } ;
225225
226- var computerName = GetVariable ( cmdlet , EnvironmentVariables . ComputerName , EnvironmentVariableTarget . Process ) ;
226+ var computerName = GetVariable ( cmdlet , EnvironmentVariables . System . ComputerName , EnvironmentVariableTarget . Process ) ;
227227
228228 // 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 )
230230 {
231231 scopeList . Add ( EnvironmentVariableTarget . User ) ;
232232 }
@@ -247,23 +247,23 @@ public static void UpdateSession(PSCmdlet cmdlet)
247247
248248 // Update PATH, combining both scopes' values.
249249 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 ) ;
252252
253- SetVariable ( cmdlet , EnvironmentVariables . Path , EnvironmentVariableTarget . Process , string . Join ( ";" , paths ) ) ;
253+ SetVariable ( cmdlet , EnvironmentVariables . System . Path , EnvironmentVariableTarget . Process , string . Join ( ";" , paths ) ) ;
254254
255255 // 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 ) ;
257257
258258 // Preserve user and architecture
259259 if ( ! string . IsNullOrEmpty ( userName ) )
260260 {
261- SetVariable ( cmdlet , EnvironmentVariables . Username , EnvironmentVariableTarget . Process , userName ) ;
261+ SetVariable ( cmdlet , EnvironmentVariables . System . Username , EnvironmentVariableTarget . Process , userName ) ;
262262 }
263263
264264 if ( ! string . IsNullOrEmpty ( architecture ) )
265265 {
266- SetVariable ( cmdlet , EnvironmentVariables . ProcessorArchitecture , EnvironmentVariableTarget . Process , architecture ) ;
266+ SetVariable ( cmdlet , EnvironmentVariables . System . ProcessorArchitecture , EnvironmentVariableTarget . Process , architecture ) ;
267267 }
268268 }
269269 }
0 commit comments