| | |
How do I read the registry?
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
The only requirement is that you should be working on a Windows OS and the compiler you use should have the required header files ( windows.h)
Also read this.
Also read this.
I don't accept change; I don't deserve to live.
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
•
•
•
•
The only requirement is that you should be working on a Windows OS and the compiler you use should have the required header files ( windows.h)
Also read this.
Good luck, LamaBot
•
•
•
•
Okay, I appreciate the help, but could someone please just give me a quick example, say I want to read from the value
"HKEY_CURRENT_USER\something\more\value"
This is a made up value of course, but how would I do it...
I want the value stored in a variable called TheValue
c Syntax (Toggle Plain Text)
#include <windows.h> #include <malloc.h> #define TOTALBYTES 8192 #define BYTEINCREMENT 1024 DWORD BufferSize = TOTALBYTES; PPERF_DATA_BLOCK PerfData = NULL; while( RegQueryValueEx( HKEY_PERFORMANCE_DATA, TEXT("Global"), NULL, NULL, (LPBYTE) PerfData, &BufferSize ) == ERROR_MORE_DATA ) { // Get a buffer that is big enough. BufferSize += BYTEINCREMENT; PerfData = (PPERF_DATA_BLOCK) realloc( PerfData, BufferSize ); }
The RegQueryValueEx retrievs the type and data of the value specified for what ever key you want to read from. Also, and just my opinion, when ever I have to write a program or script that is relatively simple I just write batch scripts using the REG command and associated operations (i.e. REG QUERY) and just check the %ERRORLEVEL% Global variable to see if a key exists. Anyway just a thought. Here is a link to the Microsoft website where you can find the above example as well as a more thorough description of RegQueryValueEx and other related Registry functions used in C\C++: http://msdn2.microsoft.com/en-us/library/ms724911.aspx
Good luck, LamaBot
Last edited by Lazaro Claiborn; Mar 7th, 2007 at 1:09 pm.
Here is another example
c Syntax (Toggle Plain Text)
#include <windows.h> #include <iostream> using namespace std; int main() { HKEY hKey = 0; char buf[255] = {0}; DWORD dwType = 0; DWORD dwBufSize = sizeof(buf); const char* subkey = "Software\\Microsoft\\Office\\PowerPoint\\AddIns\\MultiMgrAddIn.AddInDesigner1"; if( RegOpenKey(HKEY_LOCAL_MACHINE,subkey,&hKey) == ERROR_SUCCESS) { dwType = REG_SZ; if( RegQueryValueEx(hKey,"Description",0, &dwType, (BYTE*)buf, &dwBufSize) == ERROR_SUCCESS) { cout << "key value is '" << buf << "'\n"; } else cout << "can not query for key value\n"; RegCloseKey(hKey); } else cout << "Can not open key\n"; cin.ignore(); return 0; }
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
Join Date: Oct 2006
Posts: 90
Reputation:
Solved Threads: 1
•
•
•
•
Bernt.tc did you care to click the link I'd provided above? The page contains sample code. Here is an example nevertheless:
Your's is better.
You can convert the key you receive into a C++ string and then do something like:
Though its a bit crude, but I think should serve your purpose.
C++ Syntax (Toggle Plain Text)
int main (void) { using namespace std ; string key = "something \ with \ spaces ." ; for ( int i = 0, j ; i < key.length( ) ; ++ i ) { if ( key [i] == ' ' ) { for ( j = i + 1; j < key.length ( ) ; ++j ) { if ( key [j] != ' ' ) break ; } key = key.erase ( i, (j - i) ) ; } } cout << key ; getchar () ; return 0; }
Though its a bit crude, but I think should serve your purpose.
I don't accept change; I don't deserve to live.
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
![]() |
Similar Threads
- I want to manipulate the registry key values through a vb.net application (VB.NET)
- how to configure figure sql mail (MS SQL)
- VBscript in a Visual Basic Application (Visual Basic 4 / 5 / 6)
- How many Anti-spywares should one install? (Viruses, Spyware and other Nasties)
- "Suspicious Scripting" in helpctr.exe (Viruses, Spyware and other Nasties)
- Cant read IO.SYS (Windows NT / 2000 / XP)
- Problem Accessing Computer In The Same WorkGroup (Networking Hardware Configuration)
- want to install new Primary Master W2K (Windows NT / 2000 / XP)
Other Threads in the C++ Forum
- Previous Thread: help w/ implementation file please
- Next Thread: two array comparison
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays beginner binary c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll download dynamic encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelper iamthwee ifstream input int integer java lib library linkedlist linker linux loop looping loops map math matrix memory microsoft newbie news number output parameter pointer problem program programming project proxy python random read recursion recursive reference return string strings struct studio system template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






