Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

write registry on Windows 7 with VB.NET

Posted on 2009-12-21
10
Medium Priority
?
3,282 Views
Last Modified: 2012-05-08
Hi,
  I have a software in VB 2008 that needs to read/write the registry at start-up. On Windows XP, it works fine. I have migrated to Windows 7 last weekend, and now, it doesn't work anymore, I have an exception thrown at the Write registry line with the error: "Requested registry access is not allowed".

How can I fix this?

I can't modify the source code, because many other programmers uses the same code.

thanks a lot for your time and help
0
Comment
Question by:Dominic34
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 58

Expert Comment

by:McKnife
ID: 26096104
Your software requires administrative rights - what a shame :)
In xp, using a member of the local admin group was enough. In vista/2008/Win7, you need to elevate the program as well. Please inform yourself about elevation and UAC at wikipedia: http://en.wikipedia.org/wiki/User_Account_Control
0
 
LVL 15

Expert Comment

by:akhafaf
ID: 26096109
 Hi there Dominic34,,,

I can only suggest  if you can make the software  " run as Administrator" then see .

Also I found a similar case on internet which you can refer to it :
http://www.texttoolkit.com/index.php?option=com_content&view=article&id=74:visual-studio-requested-registry-access-is-not-allowed&catid=35:technology&Itemid=55

Best Wishes
0
 
LVL 22

Expert Comment

by:senad
ID: 26096180
You have to disable UAC to be able to do that.
And to successfully do it you have to reboot the machine as well.
So you will have to alter the code a little bit for the purpose....
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 58

Expert Comment

by:McKnife
ID: 26096456
A workaround would be to toggle the consent behavior of UAC - this does not require a reboot.
disable:
reg ADD HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v ConsentPromptBehaviorAdmin /t REG_DWORD /d 0 /f
reactivate:
reg ADD HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v ConsentPromptBehaviorAdmin /t REG_DWORD /d 2 /f

But this alone is not enough. To trigger scripted elevation (in a batch), you can use elevate, a powertoy by Microsoft: http://technet.microsoft.com/en-us/magazine/2008.06.elevation.aspx
0
 
LVL 58

Expert Comment

by:McKnife
ID: 26096493
Haha...
But to add anything to HKLM, you need to run elevated as well, so no chance to do this quietly scripted without a reboot.
You should attempt to use the user space instead, which won't require elevated rights.
0
 
LVL 33

Expert Comment

by:Todd Gerbert
ID: 26096996
Under Vista & Windows 7, thanks to UAC, by default even if you're logged in as an administrator, you still have limited access rights. This is to keep normal users who are in the bad habit of loggin in as an administrator from inadvertently doing damage to their system.  In addition to logging in with appropriate rights, you need to specifically ask for administrative access - you can do this by right-clicking on a shortcut or .exe and choosing the "Run as Administrator" option, you can click on properties instead, go to the compatability tab and check the "run as administrator" checkbox to always run this exe/shortcut with elevated privileges.

You should write your code to NOT assume you have administrative access, and should probably choose to write to HKCU instead of HKLM, or to use application settings so that your application does not require administrative access.

However, if you legitimately need admin access you should set UAC settings in your project, so that Windows will know it needs to run with elevated privileges, right click your project, go to properties, click UAC settings, and change requestedExecutionLevel to requireAdministrator.


Of course, all that's moot if the security permissions on the registry key in question prohibit you from writing. ;)
Untitled.png
0
 

Author Comment

by:Dominic34
ID: 26098522
Hi,

  I tried to set the "run as administrator" checkbox, but it didn't worked.

I should have mentionned that I execute the program directly from Visual Studio. I don't know if it changed anything regarding the solution...
0
 

Author Comment

by:Dominic34
ID: 26098635
tgerbert, I tried your solution, and I still have the same exception thrown:


Capture.JPG
0
 
LVL 33

Accepted Solution

by:
Todd Gerbert earned 2000 total points
ID: 26099419
You may need to start Visual Studio to "Run as Administrator..." by right-clicking on the Visual Studio shortcut.  Also make sure the user you're logged in as has write rights to HKLM\Software.

Also consider using Application Settings instead of the registry, if that's even a remote possibility.
0
 

Author Closing Comment

by:Dominic34
ID: 31668518
thanks, it works now!!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

OfficeMate Freezes on login or does not load after login credentials are input.
A quick guide on how to use Group Policy to create a custom power plan and set it active on Windows 7.
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…
Suggested Courses

576 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question