07-20-2010 04:24 AM
Hi,
I have just upgraded my development PC from Windows XP Prof to Windows 7 Prof.
This has introduced a problem with an application that was working fine on XP.
Under Windows 7 I am unable to write to the following registry key:
char * subkey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
const char * title = "OB5 Scheduler";
GetProjectDir (executablePath);
SetDir (executablePath);
strncat(executablePath , "\\" , MAX_PATHNAME_LEN - strlen(executablePath));
strncat(executablePath , argv[0] , MAX_PATHNAME_LEN - strlen(executablePath));
RegWriteString (REGKEY_HKLM, subkey, title, executablePath);
The function returns -5066 = "Could not set data for registry value".
I be grateful for pointers.
07-21-2010 10:27 AM
The registry is more protected in Windows Vista and Windows 7 than in previous versions of Windows. In order to change any key in HKLM, avoiding virtualization*, your application will need to be run with administrative privileges (right-click 'run as administrator' option). There are a number of ways of ensuring this happens automatically, perhaps the most correct being to add a manifest to the exe to requiest administrative rights each time the app. is run.
*Virtualization doesn't apply to HKLM\Software\Microsoft\Windows and sub-keys in any case.
07-21-2010 10:55 AM
Thanks for the reply Martin,
A quick search on manifest files brings up a lot of potential reading. Do you have any suggestions for a good place to start?
Thanks,
John
07-21-2010 11:42 AM
I'm no expert, but if you search for articles that also contain "requireAdministrator" (one word), you might find something useful. You are looking for some XML that will form the manifest file which you can then embed in your application using the Build|Target Settings dialog.
Microsoft have a tool called 'MageUI' which can generate manifest files, it is part of the .NET framework toolset.
07-21-2010 12:23 PM
Thanks Martin,
I'll take a look at that.
John
07-23-2010 05:14 AM
Don't forget to post your findings back here - that way we all learn ![]()
07-23-2010 05:21 AM
Will do, but this is a background task for me.
John