itopiz

itopiz

Is there a command to set a Windows service to "Automatic (Delayed Start)"?

I made an Elixir app with mix release that runs on Windows as a service.

Because of a erlsrv bug (Windows service fails to start on OS (re)boot · Issue #6076 · erlang/otp · GitHub), I manually set the service to “Automatic (Delayed Start)”.

I would like to automate this step with a command line that I could add in my installer (Inno Setup).

However, it seem that I need the true service name and not the display name to change the service to “Automatic (Delayed Start)”:

PS C:\WINDOWS\system32> sc.exe config "myapp_myapp" start=delayed-auto
[SC] OpenService FAILED 1060:

The specified service does not exist as an installed service.

PS C:\WINDOWS\system32> sc.exe config myapp01da552321887be0 start=delayed-auto
[SC] ChangeServiceConfig SUCCESS

I am not aware of the true service name when installing the service because it is generated randomly. However, there seems to be a way to get the (truncated) true service name from the display name:

PS C:\WINDOWS\system32> Get-Service -Displayname "myapp_myapp"

Status   Name               DisplayName
------   ----               -----------
Stopped  myapp01da552321... myapp_myapp

I am not so familiar with Windows scripting. Is there a way to run a command to change the service to “Automatic (Delayed Start)” with only the display name myapp_myapp as argument?

Marked As Solved

itopiz

itopiz

That works!

The full command I came up with:

for /f "usebackq" %s in (`powershell.exe -Command "Get-Service -Displayname myapp_myapp | Select -ExpandProperty Name -First 1"`) do sc.exe config %s start=delayed-auto

which translates to Inno Setup as:

[Run]
Filename: "{app}\bin\myapp.bat"; Parameters: "install"
Filename: "{cmd}"; \
  Parameters: "/c ""for /f ""usebackq"" %s in (`powershell.exe -Command ""Get-Service -Displayname myapp_myapp | Select -ExpandProperty Name -First 1""`) do sc.exe config %s start=delayed-auto"""; \
  Flags: runhidden

Where Next?

Popular in Questions Top

Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
logicmason
Hi there, I'm working through my first release with elixir/phoenix. I've built a release with distillery and found that it crashes when I...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
Fl4m3Ph03n1x
Background Let’s assume I have a typical GenServer that receives messages as requests, does some operation in a DB and returns responses....
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
Mooodi
Given a string, how can I get access to its character by index? Enum.at("my_string", 2) doesn't work. Or rather, not char, but a substr...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

Other popular topics Top

Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 27727 240
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New

We're in Beta

About us Mission Statement