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. Access Denied returned from CreateService

Access Denied returned from CreateService

Scheduled Pinned Locked Moved C / C++ / MFC
help
8 Posts 3 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.
  • N Offline
    N Offline
    Neelesh K J Jain
    wrote on last edited by
    #1

    Hello All, When I am executing the following code

    SC\_HANDLE schSCManager, schService;
    TCHAR szPath\[MAX\_PATH\];
    
    GetModuleFileName(NULL, szPath, MAX\_PATH);
    schSCManager = OpenSCManager(NULL, NULL ,SC\_MANAGER\_ALL\_ACCESS);
    
    if ( schSCManager == NULL )
    	return false;
    
    schService = CreateService(schSCManager, USER\_SERVICE\_NAME, USER\_SERVICE\_NAME,
    	SERVICE\_ALL\_ACCESS,SERVICE\_WIN32\_OWN\_PROCESS,SERVICE\_DEMAND\_START,SERVICE\_ERROR\_NORMAL, szPath, NULL, NULL, NULL, NULL, NULL);
    

    The

    CreateService()

    is not returning a proper handle. When I used

    GetLastError()

    , its throwing a

    ERROR_ACCESS_DENIED

    error. Please help in solving this issue. Thanks in advance, Neelesh K J Jain.

    S S 2 Replies Last reply
    0
    • N Neelesh K J Jain

      Hello All, When I am executing the following code

      SC\_HANDLE schSCManager, schService;
      TCHAR szPath\[MAX\_PATH\];
      
      GetModuleFileName(NULL, szPath, MAX\_PATH);
      schSCManager = OpenSCManager(NULL, NULL ,SC\_MANAGER\_ALL\_ACCESS);
      
      if ( schSCManager == NULL )
      	return false;
      
      schService = CreateService(schSCManager, USER\_SERVICE\_NAME, USER\_SERVICE\_NAME,
      	SERVICE\_ALL\_ACCESS,SERVICE\_WIN32\_OWN\_PROCESS,SERVICE\_DEMAND\_START,SERVICE\_ERROR\_NORMAL, szPath, NULL, NULL, NULL, NULL, NULL);
      

      The

      CreateService()

      is not returning a proper handle. When I used

      GetLastError()

      , its throwing a

      ERROR_ACCESS_DENIED

      error. Please help in solving this issue. Thanks in advance, Neelesh K J Jain.

      S Offline
      S Offline
      Stuart Dootson
      wrote on last edited by
      #2

      Are you executing this from an account with administrator access?

      Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

      N 1 Reply Last reply
      0
      • S Stuart Dootson

        Are you executing this from an account with administrator access?

        Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

        N Offline
        N Offline
        Neelesh K J Jain
        wrote on last edited by
        #3

        Yes, I have the administrator access. Thanks, Neelesh K J Jain.

        S 1 Reply Last reply
        0
        • N Neelesh K J Jain

          Yes, I have the administrator access. Thanks, Neelesh K J Jain.

          S Offline
          S Offline
          Stuart Dootson
          wrote on last edited by
          #4

          From the documentation[^]:

          ERROR_ACCESS_DENIED

          The handle to the SCM database does not have the SC_MANAGER_CREATE_SERVICE access right.

          That implies that when you called OpenSCManager[^], you didn't ask for the SC_MANAGER_CREATE_SERVICE access right.

          Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

          N 1 Reply Last reply
          0
          • S Stuart Dootson

            From the documentation[^]:

            ERROR_ACCESS_DENIED

            The handle to the SCM database does not have the SC_MANAGER_CREATE_SERVICE access right.

            That implies that when you called OpenSCManager[^], you didn't ask for the SC_MANAGER_CREATE_SERVICE access right.

            Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

            N Offline
            N Offline
            Neelesh K J Jain
            wrote on last edited by
            #5

            Hello Stuart, I tried even with SC_MANAGER_CREATE_SERVICE access right, then also I am getting same error code as access denied.

            S 1 Reply Last reply
            0
            • N Neelesh K J Jain

              Hello Stuart, I tried even with SC_MANAGER_CREATE_SERVICE access right, then also I am getting same error code as access denied.

              S Offline
              S Offline
              Stuart Dootson
              wrote on last edited by
              #6

              Neelesh K J Jain wrote:

              even with

              'even with'? That access right (implied by SC_MANAGER_ALL_ACCESS) is absolutely necessary for creating a service. And you did include it in your call to OpenSCManager, right?

              Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

              N 1 Reply Last reply
              0
              • N Neelesh K J Jain

                Hello All, When I am executing the following code

                SC\_HANDLE schSCManager, schService;
                TCHAR szPath\[MAX\_PATH\];
                
                GetModuleFileName(NULL, szPath, MAX\_PATH);
                schSCManager = OpenSCManager(NULL, NULL ,SC\_MANAGER\_ALL\_ACCESS);
                
                if ( schSCManager == NULL )
                	return false;
                
                schService = CreateService(schSCManager, USER\_SERVICE\_NAME, USER\_SERVICE\_NAME,
                	SERVICE\_ALL\_ACCESS,SERVICE\_WIN32\_OWN\_PROCESS,SERVICE\_DEMAND\_START,SERVICE\_ERROR\_NORMAL, szPath, NULL, NULL, NULL, NULL, NULL);
                

                The

                CreateService()

                is not returning a proper handle. When I used

                GetLastError()

                , its throwing a

                ERROR_ACCESS_DENIED

                error. Please help in solving this issue. Thanks in advance, Neelesh K J Jain.

                S Offline
                S Offline
                serzh83
                wrote on last edited by
                #7

                GetModuleFileName(NULL, szPath, MAX_PATH);
                CreateService(schSCManager, USER_SERVICE_NAME, USER_SERVICE_NAME, SERVICE_ALL_ACCESS,SERVICE_WIN32_OWN_PROCESS,SERVICE_DEMAND_START,SERVICE_ERROR_NORMAL, szPath, NULL, NULL, NULL, NULL, NULL);

                Try register service from another process

                1 Reply Last reply
                0
                • S Stuart Dootson

                  Neelesh K J Jain wrote:

                  even with

                  'even with'? That access right (implied by SC_MANAGER_ALL_ACCESS) is absolutely necessary for creating a service. And you did include it in your call to OpenSCManager, right?

                  Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

                  N Offline
                  N Offline
                  Neelesh K J Jain
                  wrote on last edited by
                  #8

                  Yes, its implied.

                  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