0

I want to start mysql server from eclipse and I need admin rights to start it, how can i do this?

import java.io.*;

public class Clasa {
   public static void main(String args[]) {
        try {
            String command = "net start MySql55";
            ProcessBuilder pb = new ProcessBuilder("cmd.exe", "/C", command);
            pb.inheritIO();
            Process pr = pb.start();
            int exitVal = pr.waitFor();
            System.out.println("Exited with error code " + exitVal);
        } catch (Exception e) {
            System.out.println(e.toString());
            e.printStackTrace();
        }
    }
}
dsh
  • 12,037
  • 3
  • 33
  • 51
Cristi
  • 1
  • 1
  • 1
  • 5
    This is really something that a scripting language ([python](http://stackoverflow.com/questions/5486725/how-to-execute-a-command-prompt-command-from-python), [batch file](http://superuser.com/questions/788924/is-it-possible-to-automatically-run-a-batch-file-as-administrator)) would be a better fit for. That being said, you can look [here](http://stackoverflow.com/questions/14596599/run-command-prompt-as-administrator) for more info on doing this in java. – F. Stephen Q Sep 01 '15 at 17:46
  • You can use "runas" command to achieve this. However your current user should have relevant permissions to do that. You can refer this https://technet.microsoft.com/en-us/library/Cc771525.aspx – Saurabh Sep 01 '15 at 18:28

1 Answers1

0

This is really something that a scripting language (python, batch file) would be a better fit for. That being said, you can look here for more info on doing this in Java.

Community
  • 1
  • 1
F. Stephen Q
  • 4,208
  • 1
  • 19
  • 42