Java 启动应用程序 [WINDOWS]

标签 java startup

我有一个简单的java代码可以关闭电脑。我可以添加什么来在 Windows 启动时运行它?

import java.io.IOException;
import java.io.OutputStream;

public class Spegni {

public static void main(String[] args) {
    Runtime runtime = Runtime.getRuntime();
    try {
        Process process = runtime.exec("C:\\WINDOWS\\system32\\cmd.exe");
        OutputStream os = process.getOutputStream();
        os.write("shutdown -s -f -t 0\n\r".getBytes());
        os.close();
        try {
            process.waitFor();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
   }  
}

最佳答案

启动,运行:

shell:startup

然后将快捷方式放在那里。快乐的拖钓。

关于Java 启动应用程序 [WINDOWS],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36700650/

相关文章:

java去除标点符号递归方法

java - 在 websphere 中启动应用程序时出现异常 java.lang.NoSuchMethodError : org/w3c/dom/Node. getTextContent()Ljava/lang/String

ios - 如何以编程方式设置 UISlider 初始值,或者,iOS 程序如何启动?

java - @Startup @Singleton Java 注释不起作用(TomEE 8 Web Profile + CentOS 7)

config - 如何在 Octave 中永久加载包?

java - java中的ByteBuffer在没有写入任何内容时返回数据,不会抛出异常

java - 什么时候应该使用 MapMaker 类的 weakValues()?

java - 警告无法激活请求的配置文件 "projectname",因为它不存在

java - 关于HotSpot中thin-locks实现中锁记录的使用

c# - 应用程序启动检查,我应该在 MVVM 模式中的什么地方执行它们?