Click to See Complete Forum and Search --> : Reading value from registry
joscollin
December 6th, 2003, 05:15 AM
Hi,
My application reads the ProxyServer string value from registry. When I run it directly, by clicking the exe, it works.
But when I run the application as a process that spawns from a service it is not querying values from registry.
RegOpenKeyEx works but RegQueryValueEx is not working and
FormatMessage gives "operation completed successfully".
Why?
vicodin451
December 6th, 2003, 11:29 AM
What is the exact registry key and value you are trying to read?
How is the app spawned by the service?
What are the credentials used by the service?
Perhaps you could also post the code in question.
Andreas Masur
December 6th, 2003, 12:51 PM
Well...post the code snippet.
In addition, you might want to take a look at the following FAQs:
How can I access the registry? (http://www.codeguru.com/forum/showthread.php?s=&threadid=247024)
How can I read data from the registry? (http://www.codeguru.com/forum/showthread.php?s=&threadid=247020)
How can I write data to the registry? (http://www.codeguru.com/forum/showthread.php?s=&threadid=247022)
joscollin
December 7th, 2003, 11:12 AM
Originally posted by vicodin451
What is the exact registry key and value you are trying to read?
How is the app spawned by the service?
What are the credentials used by the service?
Perhaps you could also post the code in question.
Registry 'String Value' I'm querying is "ProxyServer".
The value will be in the format ipaddress:portnumber.
I'm using CreateProcess to start Host.exe from a service program.
The code for createprocess is below:
-----------------------------------------------------
STARTUPINFO sinfo;
memset (&sinfo, 0, sizeof(sinfo));
char* cCmdLine = new char[MAX_PATH+1];
sinfo.cb = sizeof(STARTUPINFO);
sinfo.lpReserved = NULL;
sinfo.lpDesktop = TEXT("WinSta0\\Default");
sinfo.lpTitle =NULL;
sinfo.dwFlags = STARTF_RUNFULLSCREEN|STARTF_USESHOWWINDOW;
sinfo.cbReserved2 = 0;
sinfo.lpReserved2 = NULL;
sinfo.wShowWindow = SW_SHOW;
CreateProcess("e:\\a\\host.exe",
NULL,
NULL,
NULL,
TRUE,
CREATE_DEFAULT_ERROR_MODE | NORMAL_PRIORITY_CLASS,
NULL,
NULL,
&sinfo,
&pinfo);
----------------------------------
Sam Hobbs
December 7th, 2003, 05:10 PM
Double-check and ensure you are using GetLastError properly to ensure you are getting the relevant error code. You might actually be getting an Access Denied error.
Services run using a login that has restricted access. Probably the service does not have access to the registry key. Find the documentation of services that describes the access that services get by default and how to modify that and/or how to grant access to the service to the registry as needed.
joscollin
December 11th, 2003, 05:46 AM
Originally posted by Sam Hobbs
Find the documentation of services that describes the access that services get by default and how to modify that and/or how to grant access to the service to the registry as needed.
From where can I get the documentation for granting access to the service to the registry?
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.