Windows registry

closed account (G26pX9L8)
Hallo guys,

I need a simple piece of code that shows a registry key and the value of it. And I'm also looking for a piece of code that can change the variable. It has a really short code. Can anybody help me?
Last edited on
closed account (G26pX9L8)
yeah, but I was hoping someone still had a bit of code, because all these tutorials are always so much code.
closed account (G26pX9L8)
Can somebody help me out?
closed account (G26pX9L8)
Nobody has a little piece of code that edits the registry? :(
We're leaving the snippets of code for registry editing to the guys on the MSDN forums. The whole list of registry functions can be found here:
http://msdn.microsoft.com/en-us/library/ms724875(v=VS.85).aspx

Sorry, but as I'm not on Windows anymore, I myself cannot provide snippets with certainty that they'll work.

-Albatross
Last edited on
If we follow all of Bunny´s posts we may realize, that he/she/it is not willing to do anything on itself...

So why provide code?...

My usual advice to You: start reading and try out the code posted on the msdn... But first: start reading and understanding... if You have problems about the understanding-part come back and ask (not for the code to solve your own problem)...
closed account (G26pX9L8)
You are right and that's exactly what I always said to my old forum. But I am a Dutch guy so it's a lot harder to understand all. Therefore I will not read large portions of text then it becomes very difficult for me. I always try to learn a programming language as soon as possible by example to ask much, but that's good in many languages but not in a higher programming language like C, I see now. I appreciate your help very much and I will think about what you said next time when I post something.
Since when is C a higher language?...

Your questions have nothin to do with the fundamentals of C...

If You are refusing from reading long sentences , because You are too lazy to read them slowly and multiple times to understand them, hope is lost - in my eyes - ...

There are many others with less english experience or worse education which made it, because they had the will to...

I know dutch people who speak english perfectly... that´s no excuse...


YOu are willing to learn a programming language - it´s a language, too - which is based on the english language... why don´t you try to use some translators... ther are a lot out there...
Once , i have written a class for registry reading ,deletin, creating registry strings.
It may contain Errors or bugs. There's no warranty,

RegistryClass.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <windows.h>
#include <iostream>
#include <cstdlib>
#include <string>

class RegistryClass
{
private:
    std::string path,key ;
    HKEY hKey;
    DWORD type;
public:
    static bool CheckPathExists( std::string _path);
    static bool CheckKeyExists( std::string _path , std::string _key , DWORD _type);
    static DWORD getSize(std::string _path , std::string _key,DWORD _type); 
    static bool deleteKey(HKEY hKey , std::string keyName);
    static std::string FindPath(std::string _keyName ,std::string value , DWORD _type , std::string mainPath);
    bool createKey(std::string value);
    bool readKey(std::string &value);
    bool openKey();
    bool deleteKey();
    RegistryClass(std::string _path , std::string _key , DWORD _type);
};


RegistryClass.cpp
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include "RegistryClass.h"
#include <sstream>
#include <iomanip>

using namespace std ;
/* Checks Whethether Path Exists or not */
bool RegistryClass::CheckPathExists(std::string _path)
{
    HKEY tempKey ;
    int ret = (int)RegOpenKeyEx( HKEY_LOCAL_MACHINE,_path.c_str() , 0, KEY_READ ,&tempKey);
     
    RegCloseKey( tempKey );
    return( ret == ERROR_SUCCESS );
}
// Eksik
bool RegistryClass::CheckKeyExists(std::string _path, std::string _key, DWORD _type)
{
    RegistryClass reg = RegistryClass( _path,_key,_type);   
    string temp = string();
    
    return reg.readKey(temp);
}
std::string RegistryClass::FindPath(string _keyName ,string value , DWORD _type,string mainPath)
{
    bool flag = true;
    for( int i = 0 ; flag ; i++)
    {
        ostringstream temp(ostringstream::out);
        temp << mainPath << setfill('0') << setw(4) << i ;
        flag = RegistryClass::CheckPathExists(temp.str());
        if( flag )
        {
            RegistryClass reg = RegistryClass(temp.str(),_keyName,_type);
            string valStr;
            if( reg.readKey(valStr) && valStr == value)
                return temp.str();
        }
    }
    return string();
}
RegistryClass::RegistryClass(std::string _path , std::string _key , DWORD _type)
{
    this->path = _path ;
    this->key = _key ;
    this->type = _type ;
}
DWORD RegistryClass::getSize(std::string _path , std::string _key,DWORD _type)
{
    HKEY tempKey ;
    DWORD size = 0 ;

    int ret = (int)RegOpenKeyEx( HKEY_LOCAL_MACHINE,_path.c_str() , 0, KEY_READ ,&tempKey);
    if( ret != ERROR_SUCCESS)
        return size ;
    RegQueryValueEx( tempKey, _key.c_str() , NULL , &_type ,NULL , &size );

    return size ;
}
bool RegistryClass::openKey()
{
     int flag = (int)RegOpenKeyEx( HKEY_LOCAL_MACHINE,path.c_str() , 0, KEY_ALL_ACCESS,&hKey);     
     return ( flag == ERROR_SUCCESS );
}
bool RegistryClass::createKey(std::string value)
{
    if(!this->openKey())
        return false;
   
    //If key exists delete it
    if( RegistryClass::CheckKeyExists(this->path,this->key,this->type))
        if(!deleteKey(this->hKey,this->key))
            return false;
    //Create&Set key
    int flag = (int)RegSetValueEx(this->hKey,key.c_str(),0,REG_SZ,(const BYTE*)value.c_str(),sizeof(TCHAR)*(value.size()+1));

    RegCloseKey(this->hKey);
    return flag == ERROR_SUCCESS;
}
bool RegistryClass::deleteKey(HKEY hKey , std::string keyName)
{
    int flag = (int)RegDeleteValue(hKey,keyName.c_str());
    return ( flag == ERROR_SUCCESS );
}
bool RegistryClass::deleteKey()
{
    if(!this->openKey())
        return false;
    return RegistryClass::deleteKey(this->hKey,this->key);
}
bool RegistryClass::readKey(std::string &value)
{
    DWORD size = getSize( this->path,this->key , this->type);
    
    if( size == 0 )
        return false;
    if(!this->openKey())
        return false;
    unsigned char *temp = new unsigned char[ (int)size ];
    int flag = (int)RegQueryValueEx(this->hKey,this->key.c_str(),NULL,&type,temp,&size);
 
    if( flag != ERROR_SUCCESS )
        return false;     

    value = std::string((char *)temp);
    RegCloseKey(this->hKey);
    return true;
}

Last edited on
Topic archived. No new replies allowed.