-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathWinService.java
More file actions
38 lines (32 loc) · 1.23 KB
/
Copy pathWinService.java
File metadata and controls
38 lines (32 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package javaforce.utils;
import javaforce.*;
/** WinService : Windows Service API
*
* @author peter.quiring
*/
public class WinService {
public static boolean create(String name, String exe) {
ShellProcess sp = new ShellProcess();
String windir = System.getenv("windir");
String output = sp.run(new String[] {windir + "/system32/sc.exe", "create", name, "binPath=", exe, "start=", "auto"}, true);
return sp.getErrorLevel() == 0;
}
public static boolean delete(String name) {
ShellProcess sp = new ShellProcess();
String windir = System.getenv("windir");
String output = sp.run(new String[] {windir + "/system32/sc.exe", "delete", name}, true);
return sp.getErrorLevel() == 0;
}
public static boolean start(String name) {
ShellProcess sp = new ShellProcess();
String windir = System.getenv("windir");
String output = sp.run(new String[] {windir + "/system32/sc.exe", "start", name}, true);
return sp.getErrorLevel() == 0;
}
public static boolean stop(String name) {
ShellProcess sp = new ShellProcess();
String windir = System.getenv("windir");
String output = sp.run(new String[] {windir + "/system32/sc.exe", "stop", name}, true);
return sp.getErrorLevel() == 0;
}
}