Registry - Writing to ..Security / Auth problems

  • Thread starter Neal Rogers via .NET 247
  • Start date
N

Neal Rogers via .NET 247

Hi All

Using VB.Net
I have tried unsuccessfully (firstly with a Web App.. and IUSER_MachineName permissions ) to write to the registry.
So , now I've tried from a windows application, and same result
ie
key.SetValue("pwd", sValIn) ' = ERROR: cannot write to the registry key
("Run-time exception thrown : System.UnauthorizedAccessException - Cannot write to the registry key.")

I have set evry possible permission for every listed user on my machine to DenyNothing, and FullControl, and
in code set RegistryPermissions ..all the code is beneath.

Still, NO way I can write to registry

Anybody...???

TIA
Neal

Code....
'checks to see read functionality
key = Registry.CurrentUser.OpenSubKey("SOFTWARE\SPLUS\pwd")
key.GetValue("pwd")

Dim f As New RegistryPermission(RegistryPermissionAccess.AllAccess, _
"HKEY_CURRENT_USER\SOFTWARE")
f.AddPathList(RegistryPermissionAccess.Write, "HKEY_CURRENT_USER\SOFTWARE")
f.AddPathList(RegistryPermissionAccess.Write, "HKEY_CURRENT_USER\SOFTWARE\SPLUS")
f.AddPathList(RegistryPermissionAccess.Write, "HKEY_CURRENT_USER\SOFTWARE\SPLUS\pwd")

f.Assert()

key.SetValue("pwd", sValIn) 'cannot write to the registry key
 
N

Nicole Calinoiu

Neal,

The overload of OpenSubKey that you are using opens the key for reading
only. Try using the overload that allows you to specify that you want to
open the key for writing
(http://msdn.microsoft.com/library/e...softwin32registrykeyclassopensubkeytopic2.asp).

Even if the above does resolve the exception you are currently receiving,
you may run into further problems. The HKEY_CURRENT_USER hive is not
populated for the runtime execution context users of services (including IIS
or ASP.NET). Therefore, attempting to use a subkey of HKEY_CURRENT_USER for
your web application is unlikely to be particularly successful. If the
value is not meant to vary between users, why not use a subkey of
HKEY_LOCAL_MACHINE instead? Otherwise, you should probably consider an
alternate data store.

HTH,
Nicole
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top