CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jun 2003
    Location
    Cochin
    Posts
    364

    Reading value from registry

    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?

  2. #2
    Join Date
    Sep 2003
    Location
    Forever Gone... For Now...
    Posts
    1,515
    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.
    Thought for the day/week/month/year:
    Windows System Error 4006:
    Replication with a nonconfigured partner is not allowed.

  3. #3
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    Well...post the code snippet.

    In addition, you might want to take a look at the following FAQs:

  4. #4
    Join Date
    Jun 2003
    Location
    Cochin
    Posts
    364
    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 ipaddressortnumber.

    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);
    ----------------------------------

  5. #5
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266
    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.
    Last edited by Sam Hobbs; December 7th, 2003 at 06:12 PM.

  6. #6
    Join Date
    Jun 2003
    Location
    Cochin
    Posts
    364
    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?
    Last edited by joscollin; December 11th, 2003 at 06:48 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured