Wednesday, February 15, 2012

Error Accessing the Registry in Custom Code

I have created a custom code module that is attempting to read a registry key value using code similar to the following...

Dim regKey As Microsoft.Win32.RegistryKey
regKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\OurCompany\Group\ReportServers")

This consistently fails. I note in the event viewer a Failure Audit with the following...

Date: xx/xx/xxxx

Time: xx:xx:xx xx

Type: Failure Aud[it]

User: NT AUTHORITY\SYSTEM

Computer: RSComputerName

Source: Security

Category: Object Access

Event ID: 560

Description:

Object Open:

Object Server: Security

Object Type: Key

Object Name: \REGISTRY\USER\.DEFAULT

Handle ID: -

Operation ID: {0,66061313}

Process ID: 1164

Image File Name: C:\WINDOWS\system32\svchost.exe

Primary User Name: MyComputerName$

Primary Domain: MyDomain

Primary Logon ID: (0x0,0x3E7)

Client User Name: MyComputerName$

Client Domain: MyDomain

Client Logon ID: (0x0,0x3E7)

Accesses: MAX_ALLOWED

Privileges: -

Restricted Sid Count: 0

Access Mask: 0x2000000

I've tried granting a bunch of permissions to SYSTEM and Everyone to HKLM subkeys, to no avail. Any thoughts on what I can do to fix the problem?

Thanks in advance.

Keith Spitz

Wall Street On Demand, Inc.

This is because the VB code in report expressions is not trusted and accessing registry requires special code permissions. The standard way is to move the code that reads registry into a custom assembly, grant that assembly required code permissions (rssrvpolicy.config), assert those permissions inside the assembly and call that assembly from your report.

http://support.microsoft.com/default.aspx?scid=kb;en-us;842419

|||

Thanks -- that was the info I needed.

However, having never created a custom assembly before, it took a little work to get the job done. I found a good tutorial at http://www.c-sharpcorner.com/Code/2005/June/CustomAssemblyinRS.asp.

Keith Spitz, Wall Street On Demand, Inc.

No comments:

Post a Comment