none
Starting a service programatically on Windows Server 2008 RRS feed

  • Question

  • Hello,

    I have written an application which can run a service programmatically. This runs fine on Windows Server 2003, but isn't working on Windows Server 2008.

    I suppose it's a question of credentials/access rights.

    How my I change my code to make it work ? Specifically, how may I call this program under the appropriate user (I think it is "Local System" ?) ?

    Thanks

    I use very simple syntax, such as :

    Dim MySvc as ServiceController
    .....
    MySvc.Start
    ...
    MySvc.Stop
    etc....

    Monday, June 20, 2011 4:52 PM

Answers

  • Hi Sygrien,

    As my last post said, click once applications do not attempt to elevate to admin privileges, it is by design. I'm afraid that you need to "Run As Administrator" manually. I mean right-click->run as administrator.

    Sincerely,


    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Sygrien Friday, July 15, 2011 6:05 PM
    Wednesday, July 13, 2011 3:19 AM

All replies

  • Hi Sygrien,

     

    Welcome to the MSDN forum.

     

    I think we need some more information to ensure whether it is  a problem of access rights.

     

    May I know the error message when the application runs on Windows Server 2008? And what the service that will be started in the application is? Is the service a 32-bit or 64-bit(or in other words, what's the platform option of the service built with? AnyCPU?x86?x64?)

     

    Any more information that helps us comprehend this issue is appreciated. Thanks.

     

    Thank you for your posting and understanding.


    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, June 21, 2011 7:48 AM
  • Hello Paul,

    Thanks for your reply.

    The error message is "Impossible to start the service"

    The service is built in 32 bits, on x86 CPU. And the service runs on Windows Server 2008. If I start the service by using the "Administrative tools", "Services" screen, the service runs fine. I just want to start it from my program.

    Tuesday, June 21, 2011 9:59 AM
  •  

    Hello Sygrien,

     

    As you said, because the service is built with X86 option, I think you'd better check that whether the application is built with x86 option too. If the application was built with X64 or AnyCPU option, it will run as a 64-bit process on 64-bit Windows Server 2008. A 64-bit process could not start a 32-bit service.

     

    More information, please refer to:

    /platform (Visual Basic)


    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, June 22, 2011 5:04 AM
  • Hello Paul,

     

    All programs (service and application) are 32 bits.

    It is not a question of RUNNING the service, it is a question of STARTING the service !

    The service runs ! Yes, it runs ! When I use the "Administrative tools", "Services" screen, it does run !

     

    I simply want to start this service from a program.

    Thanks

    Wednesday, June 22, 2011 9:44 AM
  •  

    Hello Sygrien again,

     

    According to your description, we know that the application and service themselves could run without any problem.

    Now, we can do the troubling-shooting steps below:

    As I know, Server Core Role for Windows Server 2008 is not supported for ServiceController class. You can determine whether Server Core role is running on the machine.

    More information:

    ServiceController.Start Method

    Server Core for Windows Server 2008

    Determining Whether Server Core Is Running

     

    Then if it is not the problem of server core role, we could try to run the application as Administrator and disable UAC.

    http://social.msdn.microsoft.com/forums/en-US/winforms/thread/165b4bf1-1684-49de-b210-4c56c7d0a8df/

     

    I hope this can help you.


    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Paul Zhou Tuesday, July 12, 2011 8:33 AM
    • Unmarked as answer by Paul Zhou Wednesday, July 13, 2011 2:19 AM
    Thursday, June 23, 2011 3:44 AM
  •  

    Hi,

     

    I am writing to check the status of the issue on your side. Would you mind letting us know the result of the suggestions?

     

    If you have got answers, please remember to mark answer.

    If not, any more concerns, please feel free to let us know.

     

    Have a nice day!


    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, June 27, 2011 2:21 AM
  • Hello Paul,

    Sorry for this late answer.

    So, YES, it is definitely an issue related to security. The program which tries to start a service is a Click-once application. I've tried to start the "setup.exe" as an administrator, and it works perfectly !!

    So, I tried to implement the solution described in your last link (by disabling UAC), but I wasn't so successful...

    In the "app.manifest" file of my project (which I access by clicking the "View Windows Settings" button in the "Application" tab of the project properties), I found the following lines :

     

    <pre lang="x-xml">  <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
      <!-- UAC Manifest Options
       If you want to change the Windows User Account Control level replace the 
       requestedExecutionLevel node with one of the following.
    
      <requestedExecutionLevel level="asInvoker" uiAccess="false" />
      <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
      <requestedExecutionLevel level="highestAvailable" uiAccess="false" />
    
       If you want to utilize File and Registry Virtualization for backward 
       compatibility then delete the requestedExecutionLevel node.
      -->
      <requestedExecutionLevel level="asInvoker" uiAccess="false" />
      </requestedPrivileges>
    
    

     

    So I tried to change it to :

     

      <!-- UAC Manifest Options
       If you want to change the Windows User Account Control level replace the 
       requestedExecutionLevel node with one of the following.
    
      <requestedExecutionLevel level="asInvoker" uiAccess="false" />
      <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
      <requestedExecutionLevel level="highestAvailable" uiAccess="false" />
    
       If you want to utilize File and Registry Virtualization for backward 
       compatibility then delete the requestedExecutionLevel node.
      -->
      <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
      </requestedPrivileges>
    
    

     

    But I got this error at compilation time :

     

    Error	1	ClickOnce does not support the request execution level 'requireAdministrator'.	ServiceManager
    

    What should I do ??

     

     

    Thanks


    Friday, July 8, 2011 5:36 PM
  •  

    Hi,

     

    I'm afraid that click once applications do not attempt to elevate to admin privileges at runtime because they can expose the client to security elevation attacks.  It is by design. If you are using click-once application, you have to use "asInvoker" level. But the application can be elevated to a higher permission level by selecting Run as Administrator.

     

    More information, you could refer to this thread and this document.


    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, July 12, 2011 3:07 AM
  • THanks Paul,

    That's unfortunate...

    How do I select "Run as Administrator" on a clickonce application ?

    Thanks

    Tuesday, July 12, 2011 9:37 PM
  • Hi Sygrien,

    As my last post said, click once applications do not attempt to elevate to admin privileges, it is by design. I'm afraid that you need to "Run As Administrator" manually. I mean right-click->run as administrator.

    Sincerely,


    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Sygrien Friday, July 15, 2011 6:05 PM
    Wednesday, July 13, 2011 3:19 AM
  • Thank you Paul,

    This was a long but very fruitful discussion. I learned a lot.

    So I decided to give up on ClickOnce and moved to the new InstallShield utility (free version, included in VS2010).

    I was able to specify that the application should run with the Administrator privileges.

    It works now !

    Thanks

    Friday, July 15, 2011 6:05 PM