Solved

RegQueryValueEx trouble...

Posted on 1998-08-25
10
214 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
Industry Leaders: 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

Industry Leaders: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
maze travler 6 73
C++ get user from AD  (VS6) 7 111
Better understanding on C++ Class serialization and formats 9 106
Eclipse IDE - Cannot copy/paste from console output 8 387
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…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

751 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