Re: Editing Registry in WinCE 6.0

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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
.



Relevant Pages

  • Re: Editing Registry in WinCE 6.0
    ... why not just have a custom IOCTL value that your driver acts ... This reads a string value from the reg. ... Copy this registry to file. ... Why don't you just unload your driver, change registry and reload your ...
    (microsoft.public.windowsce.platbuilder)
  • Re: Registry Changes Do Not Save
    ... When you make a registry change, ... Screensaver password duration: ... Type: DWORD or STRING ... When I leave the computer running and reboot, ...
    (microsoft.public.windowsxp.general)
  • Re: Driver Question
    ... there is *no* parameter validation done on string values retrieved from the registry by "the system". ... >> This makes the driver to be a PnP driver. ...
    (microsoft.public.development.device.drivers)
  • Re: more - network connections - Broadcom device fails to start
    ... I did add the registry setting to increase the logging level for my XPe ... but there seemed to be no changes made to setupapi.log and still no driver ... Do I need to set/delete something else to get XPe to attempt to install the ... > - Reboot and check if the driver got installed. ...
    (microsoft.public.windowsxp.embedded)
  • Re: Registry Changes Do Not Save
    ... The screensaver is ok, but I don't think that saving your password in a registry ... Type: DWORD or STRING ... Right before I reboot I run the exported .reg file. ...
    (microsoft.public.windowsxp.general)