How to Make Win10 Boot-Up Self-Start Java Files


I. Problem Description

As we enter the pit of Win10, we find that the most unbearable thing about it is to force system updates, and the frequent updates are unbearable. As a result, for some Java files that want to run all the time, a reboot after each system update will cause the Java files to be unable to continue running.

There are also many blogs to solve this problem: create a bat file and put the shortcut in the C: ProgramData Microsoft Windows Start Menu Programs StartUp directory, which requires user login to boot itself, but not.

Using Instsrv.exe (which can install and delete services for the system) and Srvany.exe (which can let the program run in a service way), you can see that you don’t want to try, it’s too troublesome.

This article takes a very simple program as an example to realize the process of solving this problem!!!

II. Problem Solution

The way to solve the problem is to create a computer task planning program.

III. Preparations

For example, you need to start the following file (CSDN. java).

* Created by Yngz_Miao on 2019/6/14. 
public class CSDN {    
public static void main(String[] args) {        Writer wo = null;        
try {            
wo = new FileWriter("loginfo.log");            wo.write("Hello World!\r\n");            
 } catch (IOException e) {            e.printStackTrace();        

The main logic is to look up the loginfo. log file in the current directory and recreate it if it does not exist. Then write Hello World! In the file. The logic is simple.

How do we run this Java file? Press shift and right-click in the current directory, choose to open the command window here, and enter the command in the command line window:

java CSDN

Incidentally, if there are Chinese characters in the Java file, it is likely that errors will occur. At this point, commands are needed:

javac -encoding utf-8
java CSDN

If there is a system. out. println program in the Java file, the running GUI window of the Java program is reserved at the end of the run. Obviously, this is not what we want. At this point, you can use javaw to avoid:

javac -encoding utf-8
javaw CSDN

IV. Ba document

Ba files, similar to shell scripts on Linux systems. It is a batch file, an unformatted text file, which contains one or more commands. Simply put, running the bat file is equivalent to running all the commands one by one.

Create a CSDN.bat file: @echo offstart Java CSDNexit double-click the bat file, which is equivalent to typing and running the sentence Java CSDN on the command line.

5. Setting the bat file boot-up and self-startup

1. Right-click computer –> management, select system tools –> task planning program;

2. Choose to create a task. In the pop-up window, enter the name of the task and choose to run –> with the highest privilege, regardless of whether the user is logged in or not.

3. Switch to the trigger page and check the delay time (waiting for some system initialization to avoid errors) when starting the task selection.

4. Switch to the operation page, select the startup program, locate the bat file that needs to be operated, and determine the starting position (that is, start the command line in that directory).

5. Conditions and settings pages are adjusted according to personal habits, and the final password is entered for confirmation.

This completes the start-up of the JAVA file. This paper aims at a simple Java file. If it is a slightly more complex Java project, the whole project can be generated into a Jar file, and then use the command: java-jar CSDN.jar, then write the corresponding bat file, and reset the task plan again.

The above is the whole content of this article. I hope it will be helpful to everyone’s study, and I hope you will support developpaer more.