Elixir , how can i run a CMD command that needs admin privileges?

Viewed 55

I'm in the windows environment and I need my program to be able to run a CMD command as an administrator...

when I try to run via System.cmd the exception return is

message: Unable to remove service (not enough privileges?)

Edit:

Using iex -S mix the program works normally
but when I generate the release and work erlsrv https://www.erlang.org/doc/man/erlsrv.html

it is installed as a service on windows but a service without permissions to run on CMD

1 Answers

Typically, this is solved by giving your user a permission to run the program under your user with sudo without a password.

In /etc/sudoers:

your_user        ALL = NOPASSWD: /usr/bin/service_to_run

Then in your application:

System.cmd("sudo", ["/usr/bin/service_to_run"], env: [{"FOO", "bar"}])
Related