1 Reply Latest reply on Nov 8, 2016 11:01 AM by paulcarron

    Write a Java application that allows users to restart Windows services

    paulcarron

      Please bear with me. I haven't done any Java programming in about 10 years so this is likely to be a steep learning curve.

       

      I'd like to write a Java application that sits on a users desktop and can be used to restart one of 3 specific services on a remote windows 2012 server.

       

      My initial thought is that the service would be selected from a dropdown and the restart initiated with the click of a button.

       

      The users aren't administrators on the server so I'd like to empower them with permissions to restart these services(only these services).

       

      Can anybody please advise where I might begin with this? If there's anywhere with information on doing something similar I'd greatly appreciate it. Also, am I biting off too much too soon? Right now I'm not even sure where to begin.

       

      Anyway, learn by doing. That's always been my attitude so here's hoping!

        • 1. Re: Write a Java application that allows users to restart Windows services
          paulcarron

          Update.

           

          I've got this code:

          import java.io.*;

           

          public class AtlasServiceStartStop {

           

              public static void main(String[] args){

                  // you can pass query/start/stop to respective

                 

                  String[] command = {"cmd.exe", "/c", "sc", "\\\\10.3.0.101", "query", "\"Atlas 5.1.3580 AX2012R2 OTHER Service\""};

                  try {

                      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);

                  }

                  } catch(Exception ex) {

                  System.out.println("Exception : "+ex);

                  }

              }

          }

           

          It returns the status of the service.

           

          I can change "query" to "stop" or "start" and re run the application to stop and start the service.

           

          I'm now trying to create these as methods so I can have a query, stop and start method?

           

          I'll post the details if I figure it out myself.