0

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.

Coolcoder
  • 4,036
  • 6
  • 28
  • 35
  • Just FYI: You don't need to set your Assembly to `UNSAFE` to _use_ `Microsoft.Win32`, you only need `UNSAFE` if you are accessing certain code inside of that class and/or system resources that require it. There is probably code in the `Microsoft.Win32` namespace that will run in `SAFE` Assemblies. – Solomon Rutzky Aug 23 '15 at 18:46

2 Answers2

1

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

Will Vousden
  • 32,488
  • 9
  • 84
  • 95
0

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

Mladen Prajdic
  • 15,457
  • 2
  • 43
  • 51
  • 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 Jan 12 '10 at 11:17
  • This answer is incorrect. It is definitely possible as the `Microsoft.Win32` namespace is contained in `mscorlib.dll` which is supported. And I have use the `RegistryKey` class myself without having to register any other DLLs into SQL Server. – Solomon Rutzky Aug 23 '15 at 18:36