Solved

Writing to the HKEY_LOCAL_MACHINE in the registry with UAC turned on

Posted on 2011-03-10
8
118 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
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 41

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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 41

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 41

Expert Comment

by:pcelba
ID: 41623842
Answers are relevant, split points between https:#a35124464  and  https:#a35127344 seems to be fair.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

863 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now