How to make your own Service using PowerShell

This topic contains 4 replies, has 4 voices, and was last updated by Profile photo of Daniel Krebs Daniel Krebs 1 week, 5 days ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #54245
    Profile photo of Amar Helloween
    Amar Helloween
    Participant

    Hi All,

    I have an executable file (MyTask.exe). Now I want to make it as a service so whenever we start it in services.msc it will start the exe file and so on.

    Can anyone have any idea how this can be done.

    #54246
    Profile photo of Adam Bukowski
    Adam Bukowski
    Participant

    get-help New-Service

    #54249
    Profile photo of Amar Helloween
    Amar Helloween
    Participant

    I tried with the below command, it created the Service in Services.msc

    PS C:\windows\system32> New-Service -Name "Test" -BinaryPathName "C:\Users\amarnath.mahato\Desktop\My Docz\Backup\Powe
    hell Scripts\Exe Files\LastBootUpTime.exe -k netsvcs" -DisplayName "Test" -StartupType Manual -Description "This is a
    st service."

    Now when I am trying to start it, it throwing the below ERROR :

    The Test service failed to start due to the following error:
    The service did not respond to the start or control request in a timely fashion.

    Error code -> 1053

    Any suggestion on this.. I am running is locally, and am local admin as well?

    #54257
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    You can't just run any old executable file as a service directly. They have to be written to work that way. If you want to run something else as a service, there's an old tool called SrvAny.exe that can help with that.

    #54259
    Profile photo of Daniel Krebs
    Daniel Krebs
    Participant

    As Dave mentioned SrvAny is very old and I believe only available in equally old Windows resource kits which are difficult to get these days. You can download and use a tool which provides the same functionality but it is still under active development call NSSM – the Non-Sucking Service Manager.

    https://nssm.cc/

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.