1- namespace WebDriverManager . Helpers
1+ using Microsoft . Win32 ;
2+
3+ namespace WebDriverManager . Helpers
24{
35 using NLog ;
46 using System ;
@@ -173,7 +175,7 @@ public static void AddEnvironmentVariable(string variable)
173175 {
174176 var variableValue = Environment . GetEnvironmentVariable ( variable ) ;
175177 if ( variableValue == null || ! variableValue . Equals ( DestinationFolder ) )
176- Environment . SetEnvironmentVariable ( variable , DestinationFolder , EnvironmentVariableTarget . Machine ) ;
178+ Environment . SetEnvironmentVariable ( variable , DestinationFolder , EnvironmentVariableTarget . Process ) ;
177179 }
178180 catch ( Exception ex )
179181 {
@@ -187,20 +189,18 @@ public static void AddEnvironmentVariable(string variable)
187189 /// Update browser driver environment variable if it's already exist and different from current
188190 /// </summary>
189191 /// <param name="variable">Environment variable</param>
190- /// <param name="extendPath">Extend PATH variable with driver variable</param>
191- public static void UpdatePath ( string variable , bool extendPath = false )
192+ public static void UpdatePath ( string variable )
192193 {
193194 try
194195 {
195- if ( ! extendPath ) return ;
196196 const string name = "PATH" ;
197- var pathVariable = Environment . GetEnvironmentVariable ( name ) ;
198- var newPathVariable = pathVariable +
199- ( pathVariable != null && pathVariable . EndsWith ( ";" ) ? string . Empty : ";" ) +
200- $@ "% { variable } %" ;
201- if ( pathVariable != null && ! pathVariable . Contains ( DestinationFolder ) &&
202- ! pathVariable . Contains ( variable ) )
203- Environment . SetEnvironmentVariable ( newPathVariable , name , EnvironmentVariableTarget . Machine ) ;
197+ const string keyName = @"SYSTEM\CurrentControlSet\Control\Session Manager\ Environment" ;
198+ var pathVariable = ( string ) Registry . LocalMachine . CreateSubKey ( keyName ) ?
199+ . GetValue ( name , string . Empty , RegistryValueOptions . DoNotExpandEnvironmentNames ) ;
200+ if ( pathVariable == null ) throw new Exception ( $ "Can't get { name } variable" ) ;
201+ var newPathVariable = $ "% { variable } %; { pathVariable } " ;
202+ if ( ! pathVariable . Contains ( variable ) )
203+ Environment . SetEnvironmentVariable ( name , newPathVariable , EnvironmentVariableTarget . Process ) ;
204204 }
205205 catch ( Exception ex )
206206 {
0 commit comments