Answered powershell : new-service

  • Friday, December 07, 2012 9:25 PM
     
     

    hi !

    I used this command : new-service, like it is shown in the Posh help. The service correctly install itself but it can't start, or it starts and stops quickly...

    new-service -name TestService -binaryPathName "C:\tmp\mysoft.exe"

    I tried too like this :

    new-service -name TestService -binaryPathName "C:\tmp\mysoft.exe -k netsvcs"

    Is it something else to do more than in the Posh help ?

    Thanks for examples, and help...

All Replies

  • Friday, December 07, 2012 9:43 PM
    Moderator
     
     

    Did you start PowerShell using "Run as administrator"?


    Richard Mueller - MVP Directory Services

  • Friday, December 07, 2012 9:50 PM
     
     
    Have you checked the event logs?

    Admiral Ackbar says...

  • Saturday, December 08, 2012 12:20 PM
     
     
    Hi, yes I launch it using  "Run as administrator" and my local account is Local Administrator...
  • Saturday, December 08, 2012 12:26 PM
     
     

    It returns :

    -Error event 7009 : the overrun of delay has achieve 3000 millisecond...

    -Error event 7000 : the service hasn't respond quickly to the request...

  • Saturday, December 08, 2012 12:53 PM
     
     

    I tried the sc method :

    sc create TestService binpath= "C:\tmp\mysoft.exe"

    [SC] CreateService réussite(s)

    But the EventLog returns the same error messages...

  • Saturday, December 08, 2012 3:01 PM
    Moderator
     
     

    This isn't a scripting question, is it? It sounds more like the fact that your program doesn't run properly as a service and you need help with that. Unfortunately this is not the forum for that question.

    Bill

  • Saturday, December 08, 2012 3:09 PM
     
     

    My program is a Posh script compilated in executable file (.exe) with PowerGuiPro...

  • Saturday, December 08, 2012 3:16 PM
     
     
    What would be the specific forum in your opinion ?
  • Saturday, December 08, 2012 4:38 PM
    Moderator
     
     

    You might first try getting support from the vendor of the application that produces the executable.

    Bill

  • Saturday, December 08, 2012 5:43 PM
     
     

    My program is a Posh script compilated in executable file (.exe) with PowerGuiPro...

    You cannot use a standard EXE as a service.  It is missing a specific handler function that allows the service controller ot communicate with the process.  It must return its stqrtup sate or the SC will timeout and destroy the process.

    http://msdn.microsoft.com/en-us/library/windows/desktop/ms687413(v=vs.85).aspx


    ¯\_(ツ)_/¯

  • Saturday, December 08, 2012 5:45 PM
     
     

    Also can you confirm me that this command is correct ?

    new-service -name TestService -binaryPathName "C:\tmp\mysoft.exe"

    or this one ?

    new-service -name TestService -binaryPathName "C:\tmp\mysoft.exe -k netsvcs"

    or twice ?

    Thanks for your last answer. An have a beautiful Sunday ! ;)

  • Saturday, December 08, 2012 5:50 PM
     
     Answered

    Here is a way to do this using the Resource Kit.

    http://support.microsoft.com/kb/137890


    ¯\_(ツ)_/¯

    • Marked As Answer by Fabiio_from_26 Monday, December 10, 2012 5:09 PM
    •  
  • Saturday, December 08, 2012 6:22 PM
     
     

    Also can you confirm me that this command is correct ?

    new-service -name TestService -binaryPathName "C:\tmp\mysoft.exe"

    or this one ?

    new-service -name TestService -binaryPathName "C:\tmp\mysoft.exe -k netsvcs"

    or twice ?

    Thanks for your last answer. An have a beautiful Sunday ! ;)

    I can confirm that that won't work.

    You cannot run any standard EXEs under the 'netsvcs' service.  This service is reserved for MIcrosoft network components.

    You cannot run any standard EXE as a service using this comamnd.


    ¯\_(ツ)_/¯

  • Monday, December 10, 2012 5:08 PM
     
     
    Thanks jrv ! I tested it today and it runs this time...
  • Monday, December 10, 2012 5:36 PM
     
     
    Thanks jrv ! I tested it today and it runs this time...

    If you actually run the examples inHELP you will find that they do not work.  Use of the svchost to inject a service intoi teh system can be dangerous.  It is also likely that the service will be created but it will never start.  You will see 'StartPending' forever.

    The NewService class ius intended to be used to create workflow tasks.  The binary will be a workflow management module that is bound to teh workflow task script.

    The documentation is stillpending on this.  I suspect iti si used in management modules but not yet released for commojn use because of teh ability of this to misbehave.

    You might try checking the PowerSHell Team blog for more background on workflows.

    I have don Workflow in teh older systems.  They do similar things but the mechanosism is hidden and we only work with the compiled objects.  The WOrkflow compiler injects the correct binding code into the executable to make it work with the workflow controller.  You cannot jsut use an EXE to make this work.  It must be a special EXE or object built by the workflow system.  I suspect that PowerShell Workflow is a wrapper around this.


    ¯\_(ツ)_/¯