Thread: Another windows service question... starting/stopping

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

    Another windows service question... starting/stopping

    Hello all,

    I've created a license server program that runs in both Linux and Windows. I need it to run as a deamon/service. In Linux, that means an additional 8 lines of code, but in Windows, as you know, it's a bit more difficult. My program runs fine from the command line in Windows, but I need a bit of help getting it running as a service.

    I've done a bit of research and can install/remove the service, but getting it running as a service is proving to be a bit more difficult. If I open up the service manager, I see my service listed, but if I try to start it (by opening the properties for my service and clicking "start") I get:

    Error 1053: The service did not respond to the start or control request in a timely fashion.

    I suppose this is because I haven't written any code that tells the SCM how to start/stop it. Is there a *simple* way of doing this? Keep in mind I already have a main(), and, if at all possible would like to keep everything the way it is so it's easy to switch between windows and Linux (in other words, I don't mind adding to main, but I'd like to not completly remove it and replace it with a DWORD WINAPI main). FYI: my main:
    Code:
    int main(int argc, char *argv[]) 
    {
      while ((c = getopt(argc, argv, "c:l: p:vhirs")) != EOF){
        switch (c) {
          // bunch of switch stuff for command line arguments
         }
      }
    
      if (ioption) { // windows install
          InstallService(license_file, log_file);
          return 0;
        }
    
    #ifndef WIN32
      init_daemon();	// set this up as a daemon
    #endif
    
      oldMain(port, license_file, log_file, verbose);	// the actual stuff
    
      return (0);
    }
    so "oldMain" is what would actually be called by something that wants to start this service (if you need to specify a function). Also, The way this thing is designed is that it just sits there and "non-blockingly" waits - forever. It doesn't need to be restarted every so often (which is something that stumped me about some of the examples I came across online).

    I can post my install/remove srevice code if it helps, but it seems those are pretty standard.
    Last edited by BrianK; 03-19-2003 at 08:15 PM.

  2. #2
    Registered User
    Join Date
    Mar 2003
    Posts
    29

    Re: Another windows service question... starting/stopping

    well, i will glad if you will post the install/remove service!!!

    I don't think i can help you, but ill try...

    you can try to do:

    net start ServiceName

    on dos if you have error message there too, i think it's not you'r program...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. General question from a beginner to Windows C++ programming
    By Kontan in forum Windows Programming
    Replies: 1
    Last Post: 09-29-2006, 08:03 PM
  2. Replies: 5
    Last Post: 08-16-2006, 02:05 PM
  3. An Elementary Windows Question
    By samGwilliam in forum Windows Programming
    Replies: 7
    Last Post: 01-20-2006, 04:20 PM
  4. a question about the windows application tutorial
    By JustPlay4Fun in forum Windows Programming
    Replies: 4
    Last Post: 01-17-2005, 01:09 PM
  5. Windows 2000 Service Pack 3...
    By MrWizard in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 08-13-2002, 12:25 AM