H
H
hHup2018-04-28 21:41:54
Java
hHup, 2018-04-28 21:41:54

Writing java code on the command line

I decided to suffer garbage, and in general, here. How can I write java code in a batch file and run it. How to make the batch file run every time the PC is turned on, how to prevent the batch file from closing via (ctrl-alt-del), and how to hide the batch file after its first launch.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
res2001, 2018-04-29
@TopMetaFizick

1.Batch code you can create a text file with JAVA code: Preface
each line of Java code with the echo command and at the end with redirect operators to the file.
2. I don’t know how to compile the created file, I didn’t work with Java, I think that the JAVA SDK has a command line compiler, study its parameters and just add the appropriate command at the end of the batch file. But the JAVA SDK is not included in the JAVA JRE, which is usually installed by computer users.
3. For autorun - put in startup. There are several autoload options in Windows, google and see what suits you best.
The easiest way is to put the batch file in the current user's startup directory, but you may not need this.
4. About closing - apparently you need to prevent not closing the batch file, but closing the executable java code. In any case, this is not trivial enough and any method can be bypassed one way or another.
The easiest option is to start the second process, which will monitor whether the first one is running and if not, then start it. But there is no guarantee, because first they can beat the second, and then the first.
Perhaps you will be satisfied with the option, for example, with hiding the batch file execution window, but there is no standard way, there are non-standard options such as cmdow utilities, nircmd - they can do this (but, for example, antiviruses do not like cmdow, although this is not a virus), just you can hide the window with a simple vbs/js script - google it.
5. On the account of launching from under the administrator - there is a runas command, but it asks for a password that must be entered by hand. There are third-party options for such a utility - google it.
PS: Your Wishlist in the aggregate looks quite suspicious. And they are not solved easily.

C
Codebaker, 2018-04-28
@Codebaker

1) google how to run the compiled jar from the command line and write a batch file
2) google how the windows task scheduler works, try to create a basic-task
3) pay attention that tasks can be run on behalf of the system administrator and draw conclusions.
success in your endeavors!

Z
Zorikto Tsyrenov, 2020-08-10
@zoriktots

I myself am new to this business. But in the book it was written so for Win7.
1. Go to [Properties] PC -> On the left will be [Advanced system settings] -> The "System Properties" window will appear in the [Advanced] tab -> At the bottom of the window there will be a button "Environment Variables";
2. In this "Environment Variables" window there will be two small tables: "User Environment Variables for User" (or Administrator) and "System Variables". -> Select the second plate "System variables" and look for the [PATH] system variable there -> Click on the "Change" button -> At the very beginning in the "Variable value" column, insert the address where the program was installed [...\Java \jdk-14.0.2\bin] (For example, in my case C:\Program Files\Java\jdk-14.0. 2\bin) and be sure to put a semicolon [;] at the end. -> Press [Ok].
*if you didn't find [Path], then press the "Create" button and paste the address of the program as it was written earlier
3. And the third step. In the same table "System variables" -> Click on the "Create" button ->
in the column "Variable name" write CLASSPATH;
and in the column "Variable value" we write [.;] (without square brackets) -> OK.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question