J
Johnny Jörgensen
I've got a program where I call a method in an internal class to update the
registry. Something like this:
Program:
using System;
using System.Security.Permissions;
using Microsoft.Win32;
namespace MyNameSpace
{
public class Program
{
[STAThread]
static void Main(string[] args)
{
RegistryClass myClass = new RegistryClass();
myClass.UpdateRegistry();
}
}
}
RegistryClass:
using System;
using System.Security.Permissions;
using Microsoft.Win32;
namespace MyNameSpace
{
internal sealed class RegistryClass
{
internal void UpdateRegistry()
{
//Update HKEY_CURRENT_USER
}
}
}
I get an error when trying to update the registry saying that I don't have
sufficient permission. So I trird doing like the documentation to the
RegistryKey class says
(http://msdn2.microsoft.com/en-us/library/microsoft.win32.registrykey.aspx)
and changed the program code to:
using System;
using System.Security.Permissions;
using Microsoft.Win32;
namespace MyNameSpace
{
[assembly: RegistryPermissionAttribute(SecurityAction.RequestMinimum,
ViewAndModify = "HKEY_CURRENT_USER")]
public class Program
{
[STAThread]
static void Main(string[] args)
{
RegistryClass myClass = new RegistryClass();
myClass.UpdateRegistry();
}
}
}
It doesn't work, however. VS complains that "assembly is not a valid
attribute location for this declaration".
Where do I put it then? I think I've tried all possible locations, but to no
avail.
Can anybody tell me what I'm doing wrong? I've done a lot of programs before
that modifies the registry, and this is the first time I've run into a
security problem, so I really don't know why it happens now when it hasn't
happened before....
Cheers,
Johnny J.
registry. Something like this:
Program:
using System;
using System.Security.Permissions;
using Microsoft.Win32;
namespace MyNameSpace
{
public class Program
{
[STAThread]
static void Main(string[] args)
{
RegistryClass myClass = new RegistryClass();
myClass.UpdateRegistry();
}
}
}
RegistryClass:
using System;
using System.Security.Permissions;
using Microsoft.Win32;
namespace MyNameSpace
{
internal sealed class RegistryClass
{
internal void UpdateRegistry()
{
//Update HKEY_CURRENT_USER
}
}
}
I get an error when trying to update the registry saying that I don't have
sufficient permission. So I trird doing like the documentation to the
RegistryKey class says
(http://msdn2.microsoft.com/en-us/library/microsoft.win32.registrykey.aspx)
and changed the program code to:
using System;
using System.Security.Permissions;
using Microsoft.Win32;
namespace MyNameSpace
{
[assembly: RegistryPermissionAttribute(SecurityAction.RequestMinimum,
ViewAndModify = "HKEY_CURRENT_USER")]
public class Program
{
[STAThread]
static void Main(string[] args)
{
RegistryClass myClass = new RegistryClass();
myClass.UpdateRegistry();
}
}
}
It doesn't work, however. VS complains that "assembly is not a valid
attribute location for this declaration".
Where do I put it then? I think I've tried all possible locations, but to no
avail.
Can anybody tell me what I'm doing wrong? I've done a lot of programs before
that modifies the registry, and this is the first time I've run into a
security problem, so I really don't know why it happens now when it hasn't
happened before....
Cheers,
Johnny J.