VISTA registry question

Everything else that doesn't fall into one of the other PB categories.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

VISTA registry question

Post by srod »

Hi,

will Vista allow me to create subkeys of #HKEY_LOCAL_MACHINE and write to them - all from code?

Can't test because I don't own Vista as yet.

Thanks.
I may look like a mule, but I'm not a complete ass.
Edwin Knoppert
Addict
Addict
Posts: 1073
Joined: Fri Apr 25, 2003 11:13 pm
Location: Netherlands
Contact:

Post by Edwin Knoppert »

You may send me an exe.. as long it does not harm or dial home.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

It's okay - found the answer!

I wish to write application data which can be shared by all users. Looks like the program has to run in administrator mode to avoid the data being placed in the current users virtual store.
I may look like a mule, but I'm not a complete ass.
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post by SFSxOI »

srod wrote:It's okay - found the answer!

I wish to write application data which can be shared by all users. Looks like the program has to run in administrator mode to avoid the data being placed in the current users virtual store.
It has to run with elevated privilages which run at the system level not the administrator level, the system level has all access. Focusing on running it as a user Administrator is not a good idea because the OS can be set up with a user named Administrator which is not necessarly the elevated mode administrator, naming an account administrator doesn't just make one the administrator automatically in Vista. On Vista even the administrator doesn't automatically have full administrator rights automatically, they have to be granted. So out of the box even if the owner enables the administrator account, unless they grant their self all rights an application might fail if the owner, and the application, assumes simply enabling the administrator account grants them all rights, if the application depends on running in administrator mode and needs those rights. This is one reason Vista has the elevated privilages that can run at the system level.

Actually you want to place the data in the virtual store. If you try to place it elsewhere without using the new Vista API's for registry access you run the risk of corrupting the registry.

I probably said this all wrong, its early and I need more coffee, but to summerize what I was trying to say: run with elevated privilages and don't depend on an account called Administrator, and...place the data in the virtual store.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Thanks - that's useful to know.

What I need to do is have an application installed on just about any machine. This application writes a single entry to the registry simply containing the installation path of the application and thus allowing other applications to read this entry and locate the first app.

Just as importantly, however, is the fact that this registry entry must be readable by all users on a single computer.

Now on xp this isn't a problem. The installation program simply creates an entry under #HKEY_LOCAL_MACHINE etc.

However, with Vista, if I understand you correctly, if the installation doesn't run with 'elevated privileges' then the registry entry will be placed within the users virtual store. Now, correct me if I'm wrong, but this will mean that other users will then not be able to access this registry entry!

Any advice to get around this? I'd kind of prefer if any user could run the installation and have the 'publicly accessible' registry entry created regardless of the users account type etc.

Is this even possible?

Thanks again.
I may look like a mule, but I'm not a complete ass.
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post by SFSxOI »

srod wrote:Thanks - that's useful to know.

What I need to do is have an application installed on just about any machine. This application writes a single entry to the registry simply containing the installation path of the application and thus allowing other applications to read this entry and locate the first app.

Just as importantly, however, is the fact that this registry entry must be readable by all users on a single computer.

Now on xp this isn't a problem. The installation program simply creates an entry under #HKEY_LOCAL_MACHINE etc.

However, with Vista, if I understand you correctly, if the installation doesn't run with 'elevated privileges' then the registry entry will be placed within the users virtual store. Now, correct me if I'm wrong, but this will mean that other users will then not be able to access this registry entry!

Any advice to get around this? I'd kind of prefer if any user could run the installation and have the 'publicly accessible' registry entry created regardless of the users account type etc.

Is this even possible?

Thanks again.
OK, I see what your doing now. If you write the entry to HKEY_LOCAL_MACHINE with elevated privilages during install it will be available to the system for any user. However, your correct in that the registry entry will be in the virtual store if you don't install with elevated privilages, thats the way I understand it and seems to be the basic advice that commercial software vendors are following. Vista's UAC might get in the way here because its triggered when something wants to run with elevated privilages, it asks the person if they want to do this. There are probably ways to do this (I don't know how) but a simple one liner in the install instructions might be the eaisiest way, i've seen some software that does this for Vista, simply explain in the install instructions that the application needs to run elevated during the install and its OK to let it do this and to answer OK or Yes to the UAC prompt so you can write the registry key to the actual HKEY_LOCAL_MACHINE and not the virtual.

Of course there is a way the user can disable the UAC prompts but still maintain the operating protection of UAC with some registry entries, however, the common user probably will not do that. And...it probably would not be a good idea for a software product to do that either, although a few commercial vendors are using that method.

Now, all that being said...parts of the HKEY_LOCAL_MACHINE also run in the virtual for all users, so you could also write to the HKEY_LOCAL_MACHINE in virtual and it be available to all users but it depends on where you write to.
Last edited by SFSxOI on Thu Mar 01, 2007 1:25 am, edited 3 times in total.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Thanks, that's some good info. I think a note in the install instructions is the way to go. Anything else would probably involve some attempt to circumnavigate Vista's security features, which can't be a good thing.

Would I be correct in saying that any attempt to write to HKEY_LOCAL_MACHINE will automatically tigger Vista's UAC and then give the user the option of installing with 'elevated privileges' etc?
I may look like a mule, but I'm not a complete ass.
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post by SFSxOI »

srod wrote:Thanks, that's some good info. I think a note in the install instructions is the way to go. Anything else would probably involve some attempt to circumnavigate Vista's security features, which can't be a good thing.

Would I be correct in saying that any attempt to write to HKEY_LOCAL_MACHINE will automatically tigger Vista's UAC and then give the user the option of installing with 'elevated privileges' etc?
Yes you would be correct in saying that.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Then I'm going to say it out loud! :)

Thanks, you've been a great help.
I may look like a mule, but I'm not a complete ass.
Post Reply