我的代码如下,我创建了我的jar文件。当我从cmd执行我的jar文件时,管理员使用命令jar -jar myfile.jar
运行它。
public class ServiceStartStop {
private static String SERVICE_NAME = "TestWindowsService";
public static void main(final String[] args) {
// to start service
final String[] StartScript = {"cmd.exe", "/c", "sc", "start", SERVICE_NAME};
try {
final Runtime runtime = Runtime.getRuntime();
final Process process = runtime.exec(StartScript);
final InputStream is = process.getInputStream();
final InputStreamReader isr = new InputStreamReader(is);
final BufferedReader br = new BufferedReader(isr);
String line;
System.out.printf("Output of running %s is:", Arrays.toString(StartScript));
while ((line = br.readLine()) != null) {
System.out.println(line);
}
} catch (final IOException e) {
e.printStackTrace();
}
}
}
我得到这样的输出......
Output of running [cmd.exe, /c, sc, start, TestWindowsService] is:[SC] StartService: OpenService FAILED 5:
Access is denied.
我从这个问题中理解的是......我正在从不在行政管理中的java代码中打开我的cmd.exe
...
我怎么能解决......这个......?
感谢高级......
答案 0 :(得分:2)