Im having problems with RegSetValueEx, it is returing error 6 (ERROR_INVALID_HANDLE), but im using the (valid!!) handle that RegCreateKeyEx is returning!! (lRetVal), i am correctly registering my permissions, with AdjustTokenPrivileges... so im clueless.
As the name of the topic says, it only happens with HKEY_LOCAL_MACHINE,
and it doesnt show with HKEY_CURRENT_USER.
Any ideas?
As the name of the topic says, it only happens with HKEY_LOCAL_MACHINE,
and it doesnt show with HKEY_CURRENT_USER.
Any ideas?
Code:
'------------------------------------------------------------------------------------------------------------------------ Function GetLogoffState() As Long ON ERROR RESUME NEXT DIM RetCode AS LONG Dim hKey As Long Local Value As Dword RetCode = RegOpenKeyEx(%HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows\CurrentVersion\Policies\Explorer", 0&, %KEY_READ, hKey) If RetCode = %ERROR_SUCCESS Then 'SetLastError(0) RetCode = RegQueryValueEx(ByVal hkey, "NoLogoff", ByVal 0, %REG_DWORD, Value, 4) 'MsgBox Systemerrormessagetext(RetCode) Function = Value Exit Function END IF Function = 0 End Function '------------------------------------------------------------------------------------------------------------------------ Function ManageLogOff(CState As Dword) As Long Local lKey As Long, lSubKey As Asciiz * 128, lKeyHandle As Long, lRetVal As Dword, lDisPos As Long Local RData As String, lRet As Long lKey = %HKEY_LOCAL_MACHINE lSubKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\policies\Explorer" SetLastError(0) lKeyHandle = RegCreateKeyEx (lKey, lSubKey, 0, "", %REG_OPTION_NON_VOLATILE, %KEY_WRITE, _ ByVal %Null, lRetVal, lDisPos) MsgBox Systemerrormessagetext(lRet) '<---- No errors here. If Cstate Then RData = MkDwd$(1) & Chr$(0) Else RData = MkDwd$(0) & Chr$(0) End If SetLastError(0) lRet = RegSetValueEx (lRetVal, "NoLogoff", %Null, %REG_DWORD, ByVal StrPtr(RData), Len(RData)) MsgBox Systemerrormessagetext(lRet) '<--- Error here. refuses a handle created with a process that reported no errors... RegCloseKey lRetVal End Function
Comment