How to change the default registry root
-
Hi Geniuses, I saving the toolbar status of my MDI application using SaveBarState (_T("TBStatus")). It works fine. It stores the status in the registry here: HKEY_CURRENT_USER\Software\Local AppWizard-Generated Applications\MyApp\TBStatus
I want the status to be stored in some other place, specifically here:
HKEY_LOCAL_MACHINE\SOFTWARE\MyApplication\TBStatusWhere "HKEY_LOCAL_MACHINE\SOFTWARE\MyApplication" is the installation entry.
My aim is to remove the toolbar status entry from the registry while uninstalling the application.
If anybody could suggest me a solution, I would be grateful. Thanks in advance, Sarvan AL
-
Hi Nibu, The SetRegistryKey always stores under "HKEY_CURRENT_USER\Software". But I want to store in "HKEY_LOCAL_MACHINE\SOFTWARE\MyApp". I am using Win2000. But it needs to be done in Win98 and WinXP too. Is there anyother alternative? Thanks for your interest. Sarvan AL
-
Hi Nibu, The SetRegistryKey always stores under "HKEY_CURRENT_USER\Software". But I want to store in "HKEY_LOCAL_MACHINE\SOFTWARE\MyApp". I am using Win2000. But it needs to be done in Win98 and WinXP too. Is there anyother alternative? Thanks for your interest. Sarvan AL
Unless you have a specific need, the toolbar state shouldn't be stored in HKLM, since the UI state is a per-user thing.
--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
-
Hi Nibu, The SetRegistryKey always stores under "HKEY_CURRENT_USER\Software". But I want to store in "HKEY_LOCAL_MACHINE\SOFTWARE\MyApp". I am using Win2000. But it needs to be done in Win98 and WinXP too. Is there anyother alternative? Thanks for your interest. Sarvan AL
Sarvan AL wrote:
Is there anyother alternative?
From the Docs: If you assign a value to
m_pszRegistryKey
, it must be dynamically allocated on the heap. TheCWinApp
destructor callsfree( )
with this pointer. You many want to use the_tcsdup( )
run-time library function to do the allocating. Also, free the memory associated with the current pointer before assigning a new value. For example://First free the string allocated by MFC at CWinApp startup.
//The string is allocated before InitInstance is called.
free((void*)m_pszRegistryKey);
//Change the name of the registry key.
//The CWinApp destructor will free the memory.
m_pszRegistryKey=_tcsdup(_T(“HKEY_CURRENT_USER\\Software\\mycompany\\myapp\\thissection\\thisvalue”));
Nibu thomas Software Developer Faqs by Michael dunn
-
Hi Geniuses, I saving the toolbar status of my MDI application using SaveBarState (_T("TBStatus")). It works fine. It stores the status in the registry here: HKEY_CURRENT_USER\Software\Local AppWizard-Generated Applications\MyApp\TBStatus
I want the status to be stored in some other place, specifically here:
HKEY_LOCAL_MACHINE\SOFTWARE\MyApplication\TBStatusWhere "HKEY_LOCAL_MACHINE\SOFTWARE\MyApplication" is the installation entry.
My aim is to remove the toolbar status entry from the registry while uninstalling the application.
If anybody could suggest me a solution, I would be grateful. Thanks in advance, Sarvan AL
Use RegCreateKey to creaet the key under any root. Just you have to specify HKLM_LOCAL_MACHINE and other parameters You can set values by RegSetValue or RegSetValueEx Cab get value by : RegQueryValue or RegQueryValueEx. you can ermove entry by RegDeleteKey and RegDeleteValue. Cheers "Peace of mind through Technology"
-
Sarvan AL wrote:
Is there anyother alternative?
From the Docs: If you assign a value to
m_pszRegistryKey
, it must be dynamically allocated on the heap. TheCWinApp
destructor callsfree( )
with this pointer. You many want to use the_tcsdup( )
run-time library function to do the allocating. Also, free the memory associated with the current pointer before assigning a new value. For example://First free the string allocated by MFC at CWinApp startup.
//The string is allocated before InitInstance is called.
free((void*)m_pszRegistryKey);
//Change the name of the registry key.
//The CWinApp destructor will free the memory.
m_pszRegistryKey=_tcsdup(_T(“HKEY_CURRENT_USER\\Software\\mycompany\\myapp\\thissection\\thisvalue”));
Nibu thomas Software Developer Faqs by Michael dunn
Hi Nibu, Changing "m_pszRegistryKey" value, remains under the hierarchy "HKEY_CURRENT_USER\Software\". If I set this member variable with "HKEY_CURRENT_USER\\Software\\mycompany", the toolbar status is here: HKEY_CURRENT_USER\\Software\\HKEY_CURRENT_USER\\Software\\mycompany It not at all changing the root. It has same functionality of SetRegistryKey(..). Kindly suggest me a path to go ahead. Sarvan AL
-
Hi Nibu, Changing "m_pszRegistryKey" value, remains under the hierarchy "HKEY_CURRENT_USER\Software\". If I set this member variable with "HKEY_CURRENT_USER\\Software\\mycompany", the toolbar status is here: HKEY_CURRENT_USER\\Software\\HKEY_CURRENT_USER\\Software\\mycompany It not at all changing the root. It has same functionality of SetRegistryKey(..). Kindly suggest me a path to go ahead. Sarvan AL
The root is hard coded. So it will be fixed. One option is to override the
GetAppRegistryKey
function ofCWinApp
. The root key is hard coded here. So overriding it and returning a valid key (i.e. your key) will help. Note: From here on this will be the default key for the application. The function signature is as follows:HKEY GetAppRegistryKey();
This is the function that returns the valid key to the application. Only problem being that it's not a virtual function. :( So if you start using it from a derived class casted to a base class it won't work. So calls like
AfxGetApp()->WriteProfileString(...)
won't work as it will callCWinApp
implementation. Cast it to appropriate class and use it.
Nibu thomas Software Developer Faqs by Michael dunn
-
The root is hard coded. So it will be fixed. One option is to override the
GetAppRegistryKey
function ofCWinApp
. The root key is hard coded here. So overriding it and returning a valid key (i.e. your key) will help. Note: From here on this will be the default key for the application. The function signature is as follows:HKEY GetAppRegistryKey();
This is the function that returns the valid key to the application. Only problem being that it's not a virtual function. :( So if you start using it from a derived class casted to a base class it won't work. So calls like
AfxGetApp()->WriteProfileString(...)
won't work as it will callCWinApp
implementation. Cast it to appropriate class and use it.
Nibu thomas Software Developer Faqs by Michael dunn
Hi Nibu, Since I am a newbie to Windows Registry Handling, I am not able to grasp the things exactly. If you could explain me in detail, I'd be grateful. I'd like to know, what is happening behind HKCU and HKLM. Is it very hard to make the UI settings common to all the users? Thanks for spending your precious time for me. Sarvan AL
-
Hi Nibu, Since I am a newbie to Windows Registry Handling, I am not able to grasp the things exactly. If you could explain me in detail, I'd be grateful. I'd like to know, what is happening behind HKCU and HKLM. Is it very hard to make the UI settings common to all the users? Thanks for spending your precious time for me. Sarvan AL
Sarvan AL wrote:
Since I am a newbie to Windows Registry Handling
Then it's trouble. You'll have to learn first. Coz registry is very sensitive to changes. Any wrong action is catastrophic. It could take the entire OS down.
Sarvan AL wrote:
I am not able to grasp the things exactly
Only in the beginning.
Sarvan AL wrote:
I'd like to know, what is happening behind HKCU and HKLM.
Nothing special is going on.
Sarvan AL wrote:
Is it very hard to make the UI settings common to all the users?
Not at all. But first learn how to work with the registry. Microsoft has provided this set of functions(
WriteProfileString
is one of them) so that users don't have to break their head writing and reading values from the registry. There are some easy functions for manipulation of registry. Look at what Ganesh said. All the best.
Nibu thomas Software Developer Faqs by Michael dunn
-
Sarvan AL wrote:
Since I am a newbie to Windows Registry Handling
Then it's trouble. You'll have to learn first. Coz registry is very sensitive to changes. Any wrong action is catastrophic. It could take the entire OS down.
Sarvan AL wrote:
I am not able to grasp the things exactly
Only in the beginning.
Sarvan AL wrote:
I'd like to know, what is happening behind HKCU and HKLM.
Nothing special is going on.
Sarvan AL wrote:
Is it very hard to make the UI settings common to all the users?
Not at all. But first learn how to work with the registry. Microsoft has provided this set of functions(
WriteProfileString
is one of them) so that users don't have to break their head writing and reading values from the registry. There are some easy functions for manipulation of registry. Look at what Ganesh said. All the best.
Nibu thomas Software Developer Faqs by Michael dunn
-
Hi Nibu, I really agree with you. As you said, Windows Registry is very sensitive. That's why I didn't want to do anything trial and error. Let me learn the basics first. Thanks for your suggestion. Sarvan AL
Sarvan AL wrote:
Let me learn the basics first.
Great! It's very easy. I would recommend open up the registry and see what is inside and understand why it is there.
Sarvan AL wrote:
As you said, Windows Registry is very sensitive.
Yes it is! But it's a safe approach to use
WriteProfileString
,... and others in that group.Sarvan AL wrote:
That's why I didn't want to do anything trial and error.
Never!
**First Back Up**
:)
Nibu thomas Software Developer Faqs by Michael dunn