main.cpp


1
#include <cstdlib>
2
#include <iostream>
3
#include <string.h>
4
5
#include <windows.h>
6
#include <Winreg.h>
7
8
9
10
using namespace std;
11
12
bool getreg();
13
14
int main(int argc, char *argv[])
15
{
16
    
17
    getreg();
18
    
19
    system("PAUSE");
20
    return EXIT_SUCCESS;
21
}
22
23
bool getreg()
24
{
25
26
    HKEY    hKey        = HKEY_LOCAL_MACHINE;
27
    LPCTSTR subKey      = "HARDWARE\\DEVICEMAP\\SERIALCOMM";
28
    REGSAM  samDesired  = KEY_READ;
29
    HKEY    Result;
30
31
    DWORD   dwIndex     = 0;
32
    char    lpValueName[MAX_PATH];
33
    DWORD   lpcValueName =  MAX_PATH;
34
    BYTE    lpData[MAX_PATH];
35
    DWORD   lpcbData =  MAX_PATH;
36
37
    long ret = RegOpenKeyEx( hKey, subKey, 0, samDesired, &Result);
38
    
39
    if ( ret != ERROR_SUCCESS )
40
    {
41
        cout << "ERROR - Regestry konnte nicht geoeffnet werden" << endl;
42
        cout << ret << endl;
43
        return false;
44
    }
45
    cout << "Registry erfolgreich geoeffnet!" << endl << endl;;
46
         
47
    do
48
    {
49
      //lpcValueName =  MAX_PATH;
50
      //lpcbData =  MAX_PATH;
51
      
52
      ret = RegEnumValue( Result,
53
                          dwIndex++,
54
                          lpValueName,
55
                          &lpcValueName,
56
                          NULL,
57
                          NULL,
58
                          lpData,
59
                          &lpcbData);
60
                          
61
      if (ret == ERROR_NO_MORE_ITEMS)
62
      {
63
        
64
        cout << " ";
65
        
66
        for (int i = 0; i < lpcValueName; i++)
67
                cout << lpValueName[i];
68
        
69
        cout << "  ";
70
            
71
        for ( int i = 0 ; i < lpcbData ; i++ )
72
            {
73
                cout << lpData[i];
74
            }
75
76
          cout << endl << endl;
77
      }
78
    }
79
    while (ret != ERROR_NO_MORE_ITEMS);
80
81
    if ( RegCloseKey ( Result ) != ERROR_SUCCESS )
82
        cout << "Regestry konnte nicht geschlossen werden!" << endl;
83
    else
84
        cout << "Regestry erfolgreich geschlossen!" << endl;
85
    return true;
86
    
87
    
88
}