Solved

RegQueryValueEx trouble...

Posted on 1998-08-25
10
215 Views
Last Modified: 2010-04-10
I have created a service giving it administration rigths but still it wont read registry keys..
the key: HKEY_LOCAL_MACHINE/software/blaha/hejhej/ ,
where i read two strings and two dwords!
this mess only occurs when the program is running as a service.. btw i putted audit when a reg query failure occcurs, but it doesnt "audit" anything!
0
Comment
Question by:webrage
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +2
10 Comments
 
LVL 32

Expert Comment

by:jhance
ID: 1171163
The fact is that RegQueryValueEx does indeed work even when running as a service.  Why don't you post some of your code so that it can be examined?
0
 

Author Comment

by:webrage
ID: 1171164
strcpy(szKey, "software\\emcat\\emcat gateway service\\");
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
             szKey,
               NULL,
                 KEY_QUERY_VALUE,
                 &hkey) == ERROR_SUCCESS) {
      RegQueryValueEx(hkey,                                                    "dbconnstr",
                  NULL,
                  NULL,
                  (unsigned char *)&CONNSTR,
                  &dwsize);
      RegQueryValueEx(hkey,
                  "logname",
                  NULL,
                  NULL,
                  (unsigned char *)&logname,
                  &dwsize);
      RegQueryValueEx(hkey,
                  "dbupdate",
                  NULL,
                  NULL,
                  (unsigned char *)&dbUpdate,
                  &dwsize);
      RegQueryValueEx(hkey,
                  "dirupdate",
                  NULL,
                  NULL,
                  (unsigned char *)&dirUpdate,
                  &dwsize);
      RegCloseKey(hkey);
      } else { //it doesnt do this
        strcpy(buf,"Error reading: ");
        strcat(buf,szKey);
        strcat(buf," key in registry!");
        AddToMessageLog(TEXT(buf));        
        printf("\nError open key");
        }

but dbconnstr and the other ones have the value of ""!
and this work running as not a service! strange eh!

0
 

Author Comment

by:webrage
ID: 1171165
checking if the code looks better this way..

      
strcpy(szKey, "software\\emcat\\emcat gateway service\\");
            if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
                                     szKey,
                                     NULL,
                                     KEY_QUERY_VALUE,
                                     &hkey) == ERROR_SUCCESS) {
                  RegQueryValueEx(hkey,
                                          "dbconnstr",
                                          NULL,
                                          NULL,
                                          (unsigned char *)&CONNSTR,
                                          &dwsize);
                  RegQueryValueEx(hkey,
                                          "logname",
                                          NULL,
                                          NULL,
                                          (unsigned char *)&logname,
                                          &dwsize);
                  RegQueryValueEx(hkey,
                                          "dbupdate",
                                          NULL,
                                          NULL,
                                          (unsigned char *)&dbUpdate,
                                          &dwsize);
                  RegQueryValueEx(hkey,
                                          "dirupdate",
                                          NULL,
                                          NULL,
                                          (unsigned char *)&dirUpdate,
                                          &dwsize);
                  
                  RegCloseKey(hkey);
            } else {
                  strcpy(buf,"Error reading: ");
                  strcat(buf,szKey);
                  strcat(buf," key in registry!");
                  AddToMessageLog(TEXT(buf));
                  printf("\nError open key");
            }
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:webrage
ID: 1171166
ok sorry i hope u can read it anyway
0
 
LVL 1

Expert Comment

by:Andy_Keys
ID: 1171167
I've had problems before becuase I was not setting the MaxSize of the input buffer before calling the RegQueryValueEx()
ie. dwSize = BufferSize
ReqQuery...
then before the next read reset the value of dwsize ready for the next read

0
 
LVL 3

Expert Comment

by:LucHoltkamp
ID: 1171168
Also check if the buffer is large enough to hold the data, if the size of the keydata is bigger than dwSize, RegQueryValueEx returns an error.
You can let RegQueryValueEx set the dwSize parameter to the keydata's size by calling RegQueryValueEx with the buffer parameter set to NULL.
0
 
LVL 8

Expert Comment

by:Answers2000
ID: 1171169
The clue is the code works when the program is running normally, but fails when the program runs as a service.

This indicates it's a security problem...

The 4th parameter of RegOpenKeyEx is the security mask based on the minimum access you need.

Additionally make sure you service has rights to access the information needed
0
 

Author Comment

by:webrage
ID: 1171170
oh sorry but i have solved the problem already..
and it was Andy Keys who helped me! so Andy if
he is listning, send an answer so i can give ya points...
0
 
LVL 1

Accepted Solution

by:
Andy_Keys earned 40 total points
ID: 1171171
Gladdly!
0
 
LVL 8

Expert Comment

by:Answers2000
ID: 1171172
OK webrage

Well done Andy
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question