write to registry in vb.net and vista


S

sd

hello
I need to keep my app entry under HKEY_LOCAL_MACHINE\Software\MyApp.
(to support for all users).I need to update one key under MYApp.
When I attempt to set value for this key
My.Computer.Registry.LocalMachine.CreateSubKey("software
\MyApp").SetValue("Licence", "Success")

I get error stating Access to HKEY_LOCAL_MACHINE\Software\MYapp denied
for Vista only.For XP no problem.If for Vista I give full control to
Myapp reg folder ,everything works fine.Is it possible to create the
registry key with full controls permission in vb.net? or is there any
other way to solve this problem through vb.net.I don't want to give
permissions manually on reg key.
Thanks
 
Ad

Advertisements

C

cfps.Christian

I'd say your best way to accomplish this is to find some way to not
write to the registry. Vista's security makes it rough to write to
the registry. I know we had an app that had to be installed on a
regular user machine but because of all the registry writing we had to
give the user administrator rights which is a huge no-no.
 
D

David Anton

If you limit writing to HKEY_LOCAL_USER, then you'll be fine. It's probably
easier to modify your app to write separately per user than to switch to
using files.
--
http://www.tangiblesoftwaresolutions.com
C++ to C#
C++ to VB
C++ to Java
Java to VB & C#
Instant C#: convert VB to C#
Instant VB: convert C# to VB
Instant C++: VB, C#, or Java to C++/CLI
 
F

Family Tree Mike

I wouldn't expect you to have problems if this were run as a part of a custom
action in a setup project. It appears though you are trying to set this as
the application is run by individual users. Maybe your example is just to
help explain it, but wouldn't the license only need checking at install, and
from then on the install is considered valid? Perhaps you are implimenting a
license expiration date. If so, that could just be handled in code without
registry modification.
 
T

Tony K

I had the same problem a while back with my app. Is this app installed on a
computer that is part of a domain? I found that some of the users on the
computer couldn't run the app as well because they were not added to the
machine as a domain user but a local user only. Our IT Admin had to add
everyone as a domain user. I hope that makes sense.

Tony K.
 
B

Ben white

I am not sure if it is easier in respect to security and Vista or if
there isn't some other pitfall but I have always had an issue with
putting things in the registry if I didn't HAVE to do it. Config
files are nice but they may not suit every situation. I have solved a
similar situation by storing the value in question as an environment
variable, As long as the information isn't sensitive it can work.
 
P

Phill W.

sd said:
I need to keep my app entry under HKEY_LOCAL_MACHINE\Software\MyApp.
(to support for all users). I need to update one key under MYApp.
When I attempt to set value for this key
My.Computer.Registry.LocalMachine.CreateSubKey("software
\MyApp").SetValue("Licence", "Success")
HLKM can only be updated (reliably) on Vista by an Administrator. An
"ordinary" User /cannot/ do so.

You could separate your "licencing" function into a separate program and
launch that from your main program if it finds itself "unlicenced", but
this will still require "Elevation" and the dreaded UAC Dialog.
I get error stating Access to HKEY_LOCAL_MACHINE\Software\MYapp denied
for Vista only.For XP no problem.
"Being" an Administrator means different things on Vista than it did on XP:

On XP, logging on and "being" an Administrator meant you executed every
process /as/ an Administrator. Risky.

On Vista, logging on and "being" an Administrator counts for /nothing/.
To run any process /as/ an Administrator, you have to do so
explicitly, via the UAC Dialog.
If for Vista I give full control to Myapp reg folder ,everything
works fine.
No surprise there.
Is it possible to create the registry key with full controls
permission in vb.net?
Probably but, because you're working under HKLM, /only/ from an Elevated
process, i.e. one run /by/ and /as/ an Administrator.

BTW, Installers should always be run in this way, so that might be a
good place to think about doing this.
is there any other way to solve this problem through vb.net.
Possibilities:
Use an Elevated "licensing" program.
Don't put values under HKLM.
Don't put values into the Registry /at all/. It's getting to be a
nightmare in there.
I don't want to give permissions manually on reg key.
Good. :)

HTH,
Phill W.
 
Ad

Advertisements

Joined
Dec 2, 2008
Messages
1
Reaction score
0
Creating registry keys 'System.UnauthorizedAccessException'

If your getting the following error

A first chance exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll

on Vista while trying to create a registry key, even though you are logon as administrator.
You have to close the development environment and restart it by right clicking the shortcut to the ide and selecting run as Administrator.

And reopen your project , now you will be able to create the key.
Hope this was helpfull
 

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

Top