views:

78

answers:

2

Is there a way to get a value from the registry using a CLR procedure that doesnt involve having to registry Microsoft.Win32 as an assembly in SQL Server?

I am looking to get the DigitalProductId (I will need to decode it to a string) from the registry within a CLR proc and return it to SQL.

Supported Namespaces

CustomMarshalers
Microsoft.VisualBasic
Microsoft.VisualC
mscorlib
System
System.Configuration
System.Data
System.Data.OracleClient
System.Data.SqlXml
System.Deployment
System.Security
System.Transactions
System.Web.Services
System.Xml
System.Core.dll
System.Xml.Linq.dll

Could I use a method in mscorlib for this?

Edit: Am I missing something here? Microsoft.Win32 appears to be usable in the CLR? Edit: Yes, I was missing something. It will need to be set as an UNSAFE assembly and then signed etc before I can use Microsoft.WIn32.

A: 

you might try using Win32 api directly with RegOpenKeyEx (advapi32) http://www.pinvoke.net/default.aspx/advapi32/RegOpenKeyEx.html

Mladen Prajdic
The problem is using external or non supported libraries within a CLR. I'd have the same issue of having to register the dll as an assembly in SQL. I would like to do this using the supported namespaces only if possible.
Coolcoder
no, then i don't think it's possible.
Mladen Prajdic
A: 

By "supported namespaces" do you mean assemblies? mscorlib contains the Microsoft.Win32 namespace, which exposes the Registry type.

Will Vousden