Solved

Writing to the HKEY_LOCAL_MACHINE in the registry with UAC turned on

Posted on 2011-03-10
8
182 Views
Last Modified: 2016-05-30
In VB.Net, is there a way to write to HKEY_LOCAL_MACHINE with UAC turned on?   It works fine if UAC is off.

           
Dim regKey As Microsoft.Win32.RegistryKey
regKey = Microsoft.Win32.Registry.LocalMachine.CreateSubKey(strKey)
regKey.SetValue(strValueName, strValue)
regKey.Close()

Open in new window

0
Comment
Question by:jdressing
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 

Author Comment

by:jdressing
ID: 35094542
I accidentally included Foxpro Database Zone on this question and it won't let me remove the zone once it is added.  I wish Expert Exchange would not always default the zone to be the same as the last question. Sorry about that...
0
 
LVL 42

Expert Comment

by:pcelba
ID: 35096914
What is the reason of UAC switched on? To prevent unauthorised registry writes... and more, of course.

If you need to write into a common part of the registry then do it during installation process which also requires administrative rights and UAC messages confirmation. You should not write such contents during the application standard run.

All computers contain many additional places where you can store some user or application related info.
0
 

Author Comment

by:jdressing
ID: 35123114
Yes, UAC is supposed to block writing to the registry, but it is also supposed to prompt the user to allow it or deny it...  it is not prompting, it is just blocking.  
0
Technology Partners: 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!

 
LVL 42

Accepted Solution

by:
pcelba earned 125 total points
ID: 35124464
This is OK. Application should know about Registry writting and if UAC is switched ON then application must elevate itself to adminstrator privilages.

If you would like to read more:
http://blogs.msdn.com/b/calvin_hsia/archive/2007/04/13/add-a-manifest-to-control-your-application-vista-uac-behavior.aspx
http://www.bigresource.com/VB-Run-an-exe-with-UAC-turned-on-Vista-Issue--XTrUmJZXta.html
0
 
LVL 29

Assisted Solution

by:Olaf Doschke
Olaf Doschke earned 125 total points
ID: 35127344
UAC does not automatically prompt for elevation. Pcelba links to a very VFP specific solution, but what's generally valid is that a manifest (embedded or not) will stat, if the whole application needs elevated priviliges or not.

Without such a demand for application elevation registry write to HKEY_LOCAL_MACHINE will not cause UAC to prompt for administrative priviliges but will be redirected to a virtualstore under HKEY_LOCAL_USER\<UserID>\Machine as stated here: http://msdn.microsoft.com/en-us/library/aa965884%28VS.85%29.aspx 

This is the core of your problem and the way to prevent it is to embed a manifest into your exe requiring elevated privileges.

Heres a video showing what to do in your VB.net project to add the needed requiredExecutionLevel in the app.manifest http://www.youtube.com/watch?v=Z8JWbJzhFiY

Bye, Olaf.


0
 

Expert Comment

by:EE_AutoDeleter
ID: 41623841
I've requested that this question be deleted for the following reason:

                           
No comment has been added to this question in more than 21 days, so it is now classified as abandoned and is now flagged for deletion.


If there is a valid solution, please OBJECT and indicate the comments that are, or would otherwise lead to, a solution.


Use the specific format https:#axxxxxxxx for comment ID(s).


Also, please don't object simply because the author did not respond to your comment. While we understand this is frustrating, unfortunately we cannot force the author to return to the question. Unless you feel you have presented a valid, verifiable solution we'll simply delete the question.


Experts-Exchange Auto Deleter
0
 
LVL 42

Expert Comment

by:pcelba
ID: 41623842
Answers are relevant, split points between https:#a35124464  and  https:#a35127344 seems to be fair.
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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

630 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