CommonAppDataRegistry throws a UnauthorizedAccessException'

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
 Im writing a litle app that <u><b>reads</b></u> some values from the regestry (Installation or admin user has written these values)

When I try to access this, while running the app as a standart user I get the following exception:
System.Windows.Forms.Application.CommonAppDataRegistry threw an exception of type System.UnauthorizedAccessException
Under Admin everything works as expected.


My Test Code

<div style="border-right:#7f9db9 1px solid;border-top:#7f9db9 1px solid;font-size:11px;overflow:auto;border-left:#7f9db9 1px solid;line-height:100%! important;border-bottom:#7f9db9 1px solid;font-family:Courier New;background-color:white  
<div style="border-right:#7f9db9 1px solid;border-top:#7f9db9 1px solid;font-size:11px;overflow:auto;border-left:#7f9db9 1px solid;line-height:100%! important;border-bottom:#7f9db9 1px solid;font-family:Courier New;background-color:white
<table style="border-top-width:0px;border-left-width:0px;margin:2px 0px;width:99%;border-bottom:#eee 0px solid;border-collapse:collapse;background-color:#fff;border-right-width:0px" cellspacing=0 cellpadding=0>
<colgroup>
<col style="border-right:gray 1px solid;padding-right:5px;padding-left:10px;font-size:11px;vertical-align:top;width:5px;color:gray;font-family:Courier New;background-color:#eee;text-align:right
<col style="padding-left:10px;font-size:11px;border-bottom:#f7f7f7 1px solid;font-family:Courier New;white-space:nowrap
<tbody>
<tr>
<td><nobr>1</nobr></td>
<td><font style="font-size:11px RegistryKey rkey = Registry.LocalMachine;  </font></td></tr>
<tr>
<td><nobr>2</nobr></td>
<td style="background-color:#f7f7f7 RegistryKey test = rkey.OpenSubKey(</font><font style="color:blue "SOFTWARE\Microsoft\MyApp\1.0.0.0"</font><font style="font-size:11px );  </font></td></tr>
<tr>
<td><nobr>3</nobr></td>
<td></font><font style="color:blue string</font><font style="font-size:11px  valueFromRegestry = (</font><font style="color:blue string</font><font style="font-size:11px )test.GetValue(</font><font style="color:blue "MyAppValue"</font><font style="font-size:11px ); </font><font style="color:green //Works just fine... </font><font style="font-size:11px  </font></td></tr>
<tr>
<td><nobr>4</nobr></td>
<td style="background-color:#f7f7f7  </td></tr>
<tr>
<td><nobr>5</nobr></td>
<td>RegistryKey rkey2 = Application.CommonAppDataRegistry; </font><font style="color:green // Failes with the exception below </font><font style="font-size:11px  </font></td></tr>
<tr>
<td><nobr>6</nobr></td>
<td style="background-color:#f7f7f7 valueFromRegestry = Application.CommonAppDataRegistry.GetValue(</font><font style="color:blue "MyAppValue"</font><font style="font-size:11px ).ToString(); </font><font style="color:green // Failes with the exception below </font><font style="font-size:11px  </font></td></tr>
<tr>
<td><nobr>7</nobr></td>
<td></font><font style="color:green //System.Windows.Forms.Application.CommonAppDataRegistry threw an exception of type System.UnauthorizedAccessException</font><font style="font-size:11px  </font></td></tr></tbody></table>

My question is why?

In effect CommonAppDataRegestry points to the exect same location as the test key.

Can anyone advise me what Im doing wrong?

View the full article
 
Back
Top