Start a Windows 10 service by Java code

0

In Windows 7 I used the following method to start a Windows service in Java:

static final String CMD_START = "cmd /c net start \"";

public static int startService(String serviceName) throws Exception {
  return execCmd(CMD_START + serviceName + "\"");
}

However, after I upgraded to Windows 10 this method no longer works. Could you help me with a code that starts a Windows service and works on Windows 10?

    
asked by anonymous 04.08.2015 / 14:41

1 answer

-1

To start any OS command, the code to use is:

Runtime r = Runtime.getRuntime();
r.exec("CMD");

The command should be in the PATH of the operating system.

If the above code along with the correct PATH configuration does not allow execution, then there is some probability of it being related to permission, so it would look in other threads showing exactly this context: OS Administrator is not allowed to start a service in windows 10.

    
04.08.2015 / 15:10