0

I tested with net stop \\ComputerName "NPS Index", but displays:

The syntax of this command is: NET STOP service

The service has dependencies. The java code is:

private static void stopService(String server, String serviceName) {
    try {
//            ProcessBuilder builder = new ProcessBuilder("cmd.exe", "/c", "sc", "\\\\" + server, "stop", serviceName);
//            Process process = builder.start();
//            process.waitFor();
        String[] command = {"cmd.exe", "/c", "net", "\\\\" + server, "stop" , serviceName};
        Process process = new ProcessBuilder(command).start();
        InputStream inputStream = process.getInputStream();
        InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
        BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
        String line;
        while ((line = bufferedReader.readLine()) != null) {
            System.out.println(line);
        }
        Thread.sleep(3000);
    } catch (Exception e) {
        log.error("Error to execute commands line in cmd " + e);
    }
}

please, somebody could help me?

Tony Hinkle
  • 4,566
  • 7
  • 20
  • 33

1 Answers1

0

Are you trying to stop a service on a remote computer?

In this case the syntax is

sc \\machine stop <service>

(see How do I restart a service on a remote machine in Windows?)

You can list the service dependencies with the --EnumDepend flag.

Community
  • 1
  • 1
mjn
  • 35,561
  • 24
  • 160
  • 351
  • I need restart its dependent services. Is there any parameter for sc to include its dependent services? – Ariel Rojas Jun 08 '16 at 16:25
  • The command line would: sc \\machine stop "NPS Index" --EnumDepend, to restart the service and its dependencies? I tested, but the message "The parameter is incorrect" is displayed in cmd – Ariel Rojas Jun 08 '16 at 16:35