Re: Editing Registry in WinCE 6.0
- From: narang <lokesh.narang84@xxxxxxxxx>
- Date: Wed, 4 Mar 2009 10:15:25 -0800 (PST)
Thanks to Keano and Michel who could not post on this group so mailed
me separately...
Michel suggested me that I could get away with rebooting by just using
ActivateDeviceEx and DeactivateDevice calls to load/unload my driver.
I will try that and post my result soon.
Meanwhile posting Keano's and Michel's replies as others might find
these very useful
KEANO'S REPLY
Hi Lokesh,
They are many ways to do this, but here are some quick hints to get
you started on one method. This reads a string value from the reg.
There are loads of examples on the web for reading DWORD values etc.
I've left out the file stuff too as there is loads of this on the web.
1. Read registry. Use RegOpenKeyEx(..) and RegQueryValueEx(..). Quick
example below.
2. Copy this registry to file. When you've read the reg value you want
you could store them in CStrings and then write them to a .txt file.
3. Modify registry. Use RegSetValueEx(..) after using RegOpenKeyEx(..)
(if you haven't already used it in step 1). You can re-use the same
handle.
4. Reboot. This depends on your system I think.
5. Perform my testing. This is up to you too.
6. Restore the registry saved in step 2. Just do the opposite steps as
described above. This time you want to read from the test file, and
use RegOpenKeyEx(..) and RegSetValueEx(..) to change the values back.
HKEY hKey; // variable that receives the handle to the opened key
DWORD dwType = REG_SZ; // this means the reg value is a string
DWORD dwSize; // the size of the entry
// firstly, open the key you want to read. This is "HKLM\\Time
Zones"
if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, //key
L"Time Zones", //subkey
0, // options - always 0
0, // samDesired - always 0
&hKey)) // variable that
receives the handle to the opened key
{
/// Create a new value
wchar_t *wcTZoneName = L"GMT Standard Time";
// set the value. You have to add 1 to the data size because
the terminating NULL char in the string isn't included.
if(ERROR_SUCCESS == RegSetValueEx(hKey, //
subkey handle
L"Default", // value
name
NULL, // must
be NULL
dwType, // value
type
(LPBYTE) wcTZoneName,//
pointer to value data
(DWORD) (lstrlen(wcTZoneName)+1)*sizeof
(TCHAR))) // data size
{
printf("Reg written\n"); // or whatever you want. Just
a dummy call here...
}
// Test the reg write went ok
// This is a dummy call to get the buffer size. You have to
call RegQueryValueEx twice, first to set the dwSize variable to the
size of the string and the second time to read the string itself.
if ((ERROR_SUCCESS == RegQueryValueEx(hKey, //Handle to a
currently open key
L"Default", //Pointer to
a string containing the name of the value to query
NULL, // Must be NULL
&dwType, // Type of key
to retrieve
NULL,
&dwSize) ))
{
// allocate enough memory to hold the number of chars we
just found
BSTR bstrData = SysAllocStringByteLen(0, dwSize);
// This is the real call to retrieve the current value
if ((ERROR_SUCCESS == RegQueryValueEx(hKey, //Handle to a
currently open key
L"Default", //Pointer to
a string containing the name of the value to query
NULL, // Must be NULL
&dwType, // Type of key
to retrieve
(LPBYTE)bstrData,
&dwSize) ))
{
// store the reg value here is a CString which makes it
easy to write to file or whatever you want to do with it
CString csCurrentSetting(bstrData);
// free the memory used
SysFreeString(bstrData);
MICHEL's REPLY:
[sending my response directly to your email because it doesn't seem to
get through to the NG server]
Why don't you just unload your driver, change registry and reload your
driver again?
Saves you from having to reboot all the time...
Here's some easy code to reload your device driver, all you have to
add
is some code in between that changes the registry (RegOpenKeyEx,
RegSetValue, RegQueryValue, RegCloseKey, etc):
DEVMGR_DEVICE_INFORMATION di = {0};
di.dwSize = sizeof(di);
HANDLE hFind = FindFirstDevice(DeviceSearchByLegacyName, L"DRV1:",
&di);
if (INVALID_HANDLE_VALUE != hFind)
{
FindClose(hFind);
DeactivateDevice(di.hDevice);
// Change registry here
Sleep(3000);
HANDLE hDevice = ActivateDeviceEx(di.szDeviceKey, NULL, 0, NULL);
CloseHandle(hDevice);
}
Of course, change "DRV1:" to the name you use for your driver.
Good luck,
Michel Verhagen, eMVP
Check out my blog: http://GuruCE.com/blog
.
- Follow-Ups:
- Re: Editing Registry in WinCE 6.0
- From: Paul G. Tobey [eMVP]
- Re: Editing Registry in WinCE 6.0
- References:
- Editing Registry in WinCE 6.0
- From: narang
- Re: Editing Registry in WinCE 6.0
- From: Lal
- Re: Editing Registry in WinCE 6.0
- From: narang
- Editing Registry in WinCE 6.0
- Prev by Date: Re: Editing Registry in WinCE 6.0
- Next by Date: Re: Editing Registry in WinCE 6.0
- Previous by thread: Re: Editing Registry in WinCE 6.0
- Next by thread: Re: Editing Registry in WinCE 6.0
- Index(es):
Relevant Pages
|