Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Start service Before Login

Start service Before Login

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelp
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gothic_coder
    wrote on last edited by
    #1

    Hello All., How can i make my service to run before log in? .. Following is my code to create the service...

    BOOL InstallService()
    {
    char strDir[1024];
    SC_HANDLE schSCManager,schService;
    GetCurrentDirectory(1024,strDir);
    strcat(strDir,"\\Session_Service.exe");

        schSCManager = OpenSCManager(NULL,NULL,SC\_MANAGER\_ALL\_ACCESS);
    
    if (schSCManager == NULL) 
    	return false;
    
    LPCTSTR lpszBinaryPathName = strDir;
    
    schService = CreateService(schSCManager, 
    						   szServiceName, 
    						   szServiceName,
    						   SERVICE\_ALL\_ACCESS,  // Desired access 
    						   SERVICE\_WIN32\_OWN\_PROCESS, //Service Type
    						   SERVICE\_AUTO\_START, // Start Type
    						   SERVICE\_ERROR\_NORMAL,  // Error Control Type
    						   lpszBinaryPathName,  // Service Binary
    						   "Base", // No Load Ordering Group
    						   NULL, // No Tag Identifier
    						   NULL, // No depenencies
    						   NULL, //Local System Account
    						   NULL); // No password
    
    
    if (schService == NULL)
    	return false; 
    
    
    CloseServiceHandle(schService);
    return true;
    

    }

    _ 1 Reply Last reply
    0
    • G gothic_coder

      Hello All., How can i make my service to run before log in? .. Following is my code to create the service...

      BOOL InstallService()
      {
      char strDir[1024];
      SC_HANDLE schSCManager,schService;
      GetCurrentDirectory(1024,strDir);
      strcat(strDir,"\\Session_Service.exe");

          schSCManager = OpenSCManager(NULL,NULL,SC\_MANAGER\_ALL\_ACCESS);
      
      if (schSCManager == NULL) 
      	return false;
      
      LPCTSTR lpszBinaryPathName = strDir;
      
      schService = CreateService(schSCManager, 
      						   szServiceName, 
      						   szServiceName,
      						   SERVICE\_ALL\_ACCESS,  // Desired access 
      						   SERVICE\_WIN32\_OWN\_PROCESS, //Service Type
      						   SERVICE\_AUTO\_START, // Start Type
      						   SERVICE\_ERROR\_NORMAL,  // Error Control Type
      						   lpszBinaryPathName,  // Service Binary
      						   "Base", // No Load Ordering Group
      						   NULL, // No Tag Identifier
      						   NULL, // No depenencies
      						   NULL, //Local System Account
      						   NULL); // No password
      
      
      if (schService == NULL)
      	return false; 
      
      
      CloseServiceHandle(schService);
      return true;
      

      }

      _ Offline
      _ Offline
      _Superman_
      wrote on last edited by
      #2

      If the CreateService returns success, this is all you need for the service to start before log in. What is the problem here? Does it not start?

      «_Superman_»
      I love work. It gives me something to do between weekends.

      Microsoft MVP (Visual C++)

      Polymorphism in C

      G 1 Reply Last reply
      0
      • _ _Superman_

        If the CreateService returns success, this is all you need for the service to start before log in. What is the problem here? Does it not start?

        «_Superman_»
        I love work. It gives me something to do between weekends.

        Microsoft MVP (Visual C++)

        Polymorphism in C

        G Offline
        G Offline
        gothic_coder
        wrote on last edited by
        #3

        Yes it return success, I'm sure about this, I'm actually handling session change notifications including Logon, Logoff, Lock and Unlock... When i restart my machine then it didn't catch the logon notofication, But when i logoff and then logon again it catches and write log to support that user has logged on..

        _ 1 Reply Last reply
        0
        • G gothic_coder

          Yes it return success, I'm sure about this, I'm actually handling session change notifications including Logon, Logoff, Lock and Unlock... When i restart my machine then it didn't catch the logon notofication, But when i logoff and then logon again it catches and write log to support that user has logged on..

          _ Offline
          _ Offline
          _Superman_
          wrote on last edited by
          #4

          You could try without defining a load order group.

          «_Superman_»
          I love work. It gives me something to do between weekends.

          Microsoft MVP (Visual C++)

          Polymorphism in C

          G 1 Reply Last reply
          0
          • _ _Superman_

            You could try without defining a load order group.

            «_Superman_»
            I love work. It gives me something to do between weekends.

            Microsoft MVP (Visual C++)

            Polymorphism in C

            G Offline
            G Offline
            gothic_coder
            wrote on last edited by
            #5

            I was doing that initially, But then i saw This thread which makes me to change the CreateService...

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups