@@ -256,7 +256,19 @@ private void SetKeyInRegistryView(string keyName, RegistryView registryView) {
256256 }
257257 }
258258 } catch ( UnauthorizedAccessException ) {
259- // key exists and we can't set it
259+ // if the key already exists and can be opened, don't worry about it
260+ // (this is mainly to deal with permissions issues)
261+ try {
262+ using ( RegistryKey registryKey = OpenKeyInRegistryView ( keyName , false , registryView ) ) {
263+ if ( registryKey != null ) {
264+ return ;
265+ }
266+ }
267+ } catch {
268+ // fail silently
269+ }
270+
271+ throw ;
260272 }
261273 }
262274
@@ -341,10 +353,11 @@ private void SetValueInRegistryView(string keyName, string valueName, object val
341353 registryKey . SetValue ( valueName , value , valueKind ) ;
342354 }
343355 } catch ( UnauthorizedAccessException ) {
356+ // if the value already exists and is an exact string match, don't worry about it
357+ // (this is mainly to deal with permissions issues)
344358 try {
345359 object _value = GetValueInRegistryView ( keyName , valueName , out RegistryValueKind ? _valueKind , registryView ) ;
346360
347- // if it's an exact string match, don't worry about it
348361 if ( valueKind == _valueKind ) {
349362 if ( value is string valueString
350363 && _value is string _valueString ) {
@@ -356,6 +369,7 @@ private void SetValueInRegistryView(string keyName, string valueName, object val
356369 } catch {
357370 // fail silently
358371 }
372+
359373 throw ;
360374 }
361375 }
@@ -1018,6 +1032,10 @@ public override void Activate(string templateName) {
10181032 // key doesn't exist and we can't set it
10191033 LogExceptionToLauncher ( ex ) ;
10201034 throw new TaskRequiresElevationException ( "Setting the key \" " + keyName + "\" requires elevation." ) ;
1035+ } catch ( UnauthorizedAccessException ex ) {
1036+ // key exists and we can't set it
1037+ LogExceptionToLauncher ( ex ) ;
1038+ throw new TaskRequiresElevationException ( "Setting the key \" " + keyName + "\" requires elevation." ) ;
10211039 } catch ( InvalidOperationException ex ) {
10221040 // key marked for deletion
10231041 LogExceptionToLauncher ( ex ) ;
0 commit comments