Steeve <> wrote:
>
>Please bear with me, very premitive question.
Yes, your snippet is a textbook example of the reason why you should check
the error return codes from APIs.
>Result = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
> L"SYSTEM\\CurrentControlSet\\Services\\Mydriver ",
> 0,KEY_QUERY_VALUE,&hKey);
Here, you are asking for permission to query values from the registry.
That's all you asked for, so that's all you get.
>if( nResult == ERROR_SUCCESS )
>{
> int nMaxLen = 16;
>
> RegQueryValueEx(hKey,
> L"Password",
> NULL,(LPDWORD)&lpType,(LPBYTE)szPassword,
> (LPDWORD)&nMaxLen);
>
> printf("Old password %S",szPassword);
>
> nMaxLen=6;
>
> RegSetValueEx(hKey,
> L"NewPassword",
> NULL,REG_SZ,(BYTE *)szNewPassword,
> nMaxLen);
Here you are trying to change the value. You didn't ask for permission to
change the value. This API fails, but since you don't check the error
codes, you don't realize it.
If you want to write the value, ask for KEY_READ|KEY_WRITE.
--
Tim Roberts,
Providenza & Boekelheide, Inc.