• 0

[C#] RegistryPermission


Question

Ok, I'm trying to code an ActiveX Component that checks if my program is installed on a pc.

Therefor I need to acces the registry.

But when I try to acces the registry it throws a SecurityException.

Here's my current piece of code taken from msdn.

RegistryPermission f = new RegistryPermission(
RegistryPermissionAccess.Read,
"HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0"); 	 
 	 
RegistryKey key = Registry.LocalMachine.OpenSubKey("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0");

It doesn't work. Which does not suprise me, honestly.

How can I make it so my ActiveX Component asks the user for permission?

Also, currently my component is a dll. I saw components flying around on the net in cabs, can I simply pack my dll into a cab or how does that work?

k0zy

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

Well, first of all, you're not making an ActiveX control. You cannot write an ActiveX control in C# (you can, however make a .NET assembly function like an ActiveX control on a website, which is probably what you're actually trying to do).

As for the answers to your questions: no, you cannot ask the user for the permission. That is set using the machine's policy settings, which you do not have programmatic access to. You'll have to convince your visitors to make that change to their configuration manually if you want to access the registry from your control (personally I don't think you'll convince too many, since that's a huge security risk).

Second, I don't think it's possible to pack a .NET assembly into a CAB file like you can with ActiveX controls.

Edited by gameguy
Link to comment
Share on other sites

  • 0

Yes, I know that I can't create ActiveX Controls. I even was unable to select a Component Control Library, solved it by dowloading an example project.

So my project is basicly impossible to realize with C#/.NET?

Is there a chance I can realize it with c++ or vb without .NET?

Do I need to write an ActiveX Control?

Thanks for your answer!!!

k0zy

Link to comment
Share on other sites

  • 0

It's not impossible with C#. Just very very difficult. The runtime is set up by default not to allow access to most areas of the system (registry, file system, etc) from remote locations. And there are very good reasons for that.

You could do it in C++, but with the new security settings in SP2, users will have to specifically authorize your control.

Link to comment
Share on other sites

  • 0

I understand the reasons why this is very hard to do!

Would be very bad if someone abuses this.

Well, looks like I'll give up on C# in the matter of creating ActiveX things.

I can't tell all my users to lower their security settings.

k0zy

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.