Solved

RegQueryValueEx trouble...

Posted on 1998-08-25
10
211 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
  • 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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 

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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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 learn how to clear a vector as well as how to detect empty vectors in C++.

832 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