1
- namespace WebDriverManager . Helpers
1
+ using Microsoft . Win32 ;
2
+
3
+ namespace WebDriverManager . Helpers
2
4
{
3
5
using NLog ;
4
6
using System ;
@@ -173,7 +175,7 @@ public static void AddEnvironmentVariable(string variable)
173
175
{
174
176
var variableValue = Environment . GetEnvironmentVariable ( variable ) ;
175
177
if ( variableValue == null || ! variableValue . Equals ( DestinationFolder ) )
176
- Environment . SetEnvironmentVariable ( variable , DestinationFolder , EnvironmentVariableTarget . Machine ) ;
178
+ Environment . SetEnvironmentVariable ( variable , DestinationFolder , EnvironmentVariableTarget . Process ) ;
177
179
}
178
180
catch ( Exception ex )
179
181
{
@@ -187,20 +189,18 @@ public static void AddEnvironmentVariable(string variable)
187
189
/// Update browser driver environment variable if it's already exist and different from current
188
190
/// </summary>
189
191
/// <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 )
192
193
{
193
194
try
194
195
{
195
- if ( ! extendPath ) return ;
196
196
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 ) ;
204
204
}
205
205
catch ( Exception ex )
206
206
{
0 commit comments