registry, services & command line arguments.. ?

This is a discussion on registry, services & command line arguments.. ? within the Windows Programming forums, part of the Platform Specific Boards category; I've made a little server app that has to run (as a daemon/service) on Linux, Irix, and Windows. Everything is ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    72

    registry, services & command line arguments.. ?

    I've made a little server app that has to run (as a daemon/service) on Linux, Irix, and Windows. Everything is done with the exeption of making it run as a service in Windows.

    My question for the impatient is: Can I pass arguments to a program pointed to by a key in the registry; using the arguments in the same way that you would if you ran the program from a command line?

    More detailed version of the question: In trying to keep the code more readable and the port to windows easier, I've kept the getopt function in my program by using the gnu getopt.c/h. In case you're not familiar, getopt parses arguments on the command line in such a way that you can send as many or as few arguments as you'd like to the program at execution. If I understand things correctly, to make a program run as a service in Windows, I simply need to link to the program from HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\Curr entVersion\RunServices. If that is the case, is there a way I can send -l foo -c bar and so on to the program through that key in the registry?

    If not, does anyone have any other clever methods for getting those arguments to the program (I suppose I could make system environment variables - I think those are active before login?)

  2. #2
    Registered User
    Join Date
    Oct 2002
    Posts
    72
    bump... this problem has reared its ugly head again... any ideas?

    Also, to extend the question justa tad more - is my method for making a program run as a service correct? Just link it in the registry? Does there need to be any sort forking or anything like there does in a Linux daemon?

    thanks
    Last edited by BrianK; 03-03-2003 at 04:57 PM.

  3. #3
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Originally posted by BrianK
    bump... this problem has reared its ugly head again... any ideas?

    Also, to extend the question justa tad more - is my method for making a program run as a service correct? Just link it in the registry? Does there need to be any sort forking or anything like there does in a Linux daemon?

    thanks
    <disclaimer>Without trying.......</disclaimer>

    If you install yourm service using CreateService(), then you can specify arguments in the lpBinaryPathName param....

  4. #4
    Registered User
    Join Date
    Oct 2002
    Posts
    72
    Originally posted by Fordy
    <disclaimer>Without trying.......</disclaimer>

    If you install yourm service using CreateService(), then you can specify arguments in the lpBinaryPathName param....
    ... interesting. I knew nothing about this. It appears you create a second program that runs once to tell Windows about a program you want to run as a service? So this would be a program that you run as a part of an installer for the original program?

    from MSDN:
    Code:
    VOID CreateSampleService() 
    { 
        LPCTSTR lpszBinaryPathName = 
            "%SystemRoot%\\system\\testserv.exe"; 
     
        schService = CreateService( 
            schSCManager,              // SCManager database 
            "Sample_Srv",              // name of service 
            lpszDisplayName,           // service name to display 
            SERVICE_ALL_ACCESS,        // desired access 
            SERVICE_WIN32_OWN_PROCESS, // service type 
            SERVICE_DEMAND_START,      // start type 
            SERVICE_ERROR_NORMAL,      // error control type 
            lpszBinaryPathName,        // service's binary 
            NULL,                      // no load ordering group 
            NULL,                      // no tag identifier 
            NULL,                      // no dependencies 
            NULL,                      // LocalSystem account 
            NULL);                     // no password 
     
        if (schService == NULL) 
            MyErrorExit("CreateService"); 
        else 
            printf("CreateService SUCCESS.\n"); 
     
        CloseServiceHandle(schService); 
    }
    ... this is a function that would be in the service installer, correct? Anyone ever used it before? Want to give a hint or two as to what the rest of that service installer program would look like?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. GradeInfo
    By kirksson in forum C Programming
    Replies: 23
    Last Post: 07-16-2008, 04:27 PM
  2. command line arguments
    By vurentjie in forum C Programming
    Replies: 3
    Last Post: 06-22-2008, 07:46 AM
  3. NULL arguments in a shell program
    By gregulator in forum C Programming
    Replies: 4
    Last Post: 04-15-2004, 11:48 AM
  4. Registry Access
    By ExDigit in forum Windows Programming
    Replies: 3
    Last Post: 01-04-2002, 04:02 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21