Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 1st, 2008, 8:22 PM   #11
KuraKai
Newbie
 
Join Date: Mar 2008
Posts: 25
Rep Power: 0 KuraKai is on a distinguished road
Re: RegQueryValue Issues

Ok, I am a little lost on this one now. I never liked MSDN...so for example lets say we have two values. One is named hexData and then the other is stringData, and we want to read them into hexBuff and the other one into stringBuff. How would i put that into this. It would use MyKey and then the first one will be 0 and the second one will be 1 for the next value. And after that I get lost to how they want to go about doing the rest, any help Ancient Dragon? Also thank you alot for the help so far, and sorry for the slowness on this.
KuraKai is offline   Reply With Quote
Old Mar 1st, 2008, 9:41 PM   #12
Ancient Dragon
PFO God In Training
 
Ancient Dragon's Avatar
 
Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 598
Rep Power: 4 Ancient Dragon is on a distinguished road
Re: RegQueryValue Issues

I have deleted the test data in my registry but I think this will work
int main(int argc, char *argv[])
{
    HKEY MyKey = 0;
    
    BYTE szBuff[255] = {0};
    char szStringBuff[255] = {0};
    char szValueName[255] = {0};
    DWORD cb = 0;
    DWORD dwType = REG_SZ;
    LONG rval;
    if (RegOpenKey(HKEY_CURRENT_USER, "Software\\Random\\Program", &MyKey) == ERROR_SUCCESS)
    {
       cout << "Program is installed\n";
       cb = sizeof(szBuff);
       
       //Debug info, this normally isn't here!
       DWORD index = 0;
       DWORD dwValueNameSize = sizeof(szValueName);
        rval = RegEnumValue(MyKey, index, szValueName, &dwValueNameSize, 0, &dwType, szBuff, &cb);
        while(rval == ERROR_SUCCESS)
        {
            cout << szValueName << ": " << szBuff << "\n";
            // sqValueName is the name of the key
            if( stricmp(szValueName,"hexBuff") == 0)
                strcpy((char *)szBuff, szValueName);
            else if( stricmp(szValueName, "stringBuff") == 0)
                strcpy(szStringBuff, szValueName);
            // increment index counter to get next key
            index++;
            dwValueNameSize = sizeof(szValueName);
            rval = RegEnumValue(MyKey, index, szValueName, &dwValueNameSize, 0, &dwType, szBuff, &cb);
       }
       printf("%d",rval);
       cout << '\n';

       RegCloseKey(MyKey);
    }

    system("PAUSE");
    return EXIT_SUCCESS;
}
__________________
<<Freelance Programmer>> << Hobby Site>>
Ancient Dragon is offline   Reply With Quote
Old Mar 1st, 2008, 10:40 PM   #13
KuraKai
Newbie
 
Join Date: Mar 2008
Posts: 25
Rep Power: 0 KuraKai is on a distinguished road
Re: RegQueryValue Issues

Ok I cleaned up the code a bit, this is only to list every values in the key.
C++ Syntax (Toggle Plain Text)
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include "windows.h"
  4. #include "winnt.h"
  5. #include "winreg.h"
  6.  
  7.  
  8. using namespace std;
  9.  
  10. int main(int argc, char *argv[])
  11. {
  12. HKEY myKey = 0;
  13.  
  14. char szValueBuff[255] = {0};
  15. char szValueName[255] = {0};
  16.  
  17. DWORD dwType = REG_SZ;
  18.  
  19. if(RegOpenKey(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon", &myKey) == ERROR_SUCCESS)
  20. {
  21. cout << "Windows is installed!(Duh!)\n";
  22.  
  23. DWORD index = 0;
  24. DWORD dwValueNameSize = sizeof(szValueName);
  25. DWORD dwValueBuffSize = sizeof(szValueBuff);
  26. while(RegEnumValue(myKey, index, szValueName, &dwValueNameSize, 0,
  27. &dwType, (byte *)szValueBuff, &dwValueBuffSize) == ERROR_SUCCESS)
  28. {
  29. cout << szValueName << " : " << szValueBuff << "\n";
  30. index++;
  31. }
  32.  
  33. cout << "Error - ";
  34. cout << RegEnumValue(myKey, index, szValueName, &dwValueNameSize, 0,
  35. &dwType, (byte *)szValueBuff, &dwValueBuffSize);
  36. cout << '\n';
  37.  
  38. RegCloseKey(myKey);
  39. }
  40.  
  41. system("PAUSE");
  42. return EXIT_SUCCESS;
  43. }
This for me returns...
Windows is installed!(Duh!)
ParseAutoexec : 1
Error - 234
Press any key to continue . . .
But there are other values there that aren't being found. Also the constant resizing of the buffsizes value is pointless being that they never change through out this.
KuraKai is offline   Reply With Quote
Old Mar 1st, 2008, 11:36 PM   #14
Ancient Dragon
PFO God In Training
 
Ancient Dragon's Avatar
 
Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 598
Rep Power: 4 Ancient Dragon is on a distinguished road
Re: RegQueryValue Issues

>>Also the constant resizing of the buffsizes value is pointless being that they never change through out this
That's needed because RegEnumValue() changes the variable to the actual length of the text inserted into the destination buffer (the string may or may not be null-terminated). So you have to change it back to the original value before calling RegEnumValue() again.

Quote:
lpcbData
A pointer to a variable that specifies the size of the buffer pointed to by the lpData parameter, in bytes. When the function returns, this variable contains the size of the data copied to lpData.
__________________
<<Freelance Programmer>> << Hobby Site>>
Ancient Dragon is offline   Reply With Quote
Old Mar 2nd, 2008, 12:12 AM   #15
KuraKai
Newbie
 
Join Date: Mar 2008
Posts: 25
Rep Power: 0 KuraKai is on a distinguished road
Re: RegQueryValue Issues

Alrighty then, at first adding that first resize doesn't make it work. However there was a secondary one that was needed.
c++ Syntax (Toggle Plain Text)
  1. while(RegEnumValue(myKey, index, szValueName, &dwValueNameSize, 0,
  2. &dwType, (byte *)szValueBuff, &dwValueBuffSize) == ERROR_SUCCESS)
  3. {
  4. cout << szValueName << " : " << szValueBuff << "\n";
  5. index++;
  6. dwValueNameSize = sizeof(szValueName);
  7. dwValueBuffSize = sizeof(szValueBuff);
  8. }
That one makes it work, I guess I saw the first one as pointless cause with or without it there was no further progress. But now that you mentioned that i guess the other one had to be resized also. That lists all of them with it.
KuraKai is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
LWP form Data array issues Johnmcter Perl 0 Feb 13th, 2008 3:21 PM
Intermittent issues blud Community Announcements and Feedback 3 Nov 2nd, 2007 9:46 AM
Table issues... Glastea HTML / XHTML / CSS 2 Jan 12th, 2007 2:54 AM
I have an idea, but copyright issues. Booooze Project Ideas 25 Aug 3rd, 2006 10:31 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:02 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC