import java.io.IOException;
import java.io.InputStream;
public class Test {
public static void main(String[] args) throws IOException {
String key = "\"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\"";
String name = "SimpleTimerServer";
String value = "\"D:\\JAVA\\My Own Developed\\Simple Time Server\\simpletimeserver.jar\"";
String command = "reg add " + key + " /v " + name + " /d " + value;
Process process = Runtime.getRuntime().exec(command);
InputStream ts = process.getErrorStream();
StringBuffer out = new StringBuffer();
byte[] b = new byte[1024];
int read = ts.read(b);
while ( (read = ts.read(b)) != -1) {
out.append(new String(b, 0, read));
}
System.out.println(new String(out));
}
}
如此,可开机启动,但对于vista等需要以管理员身份运行的貌似此程序无能为力,详细的命令行注册表操作见:
http://blog.sina.com.cn/s/blog_4ce10d880100ilxe.html
以上cmd为:reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /v SimpleTimerServer /d "D:\JAVA\My Own Developed\Simple Time Server\simpletimeserver.jar"
留待进一步解决...