简体   繁体   中英

making a batch file to install a program

One of my friend told me that he used a batch program to install a java program on the machine,that placed the necessary files in a particular directory and also planted a shortcut on the desktop. How can it be done ? If there are tutorials that teach this please link me to them

All you need to do is use some basic windows commands to make this work. I'm not going to write the script for you but I can point you in the right direction. A batch script on windows is a simple text file ending with the .bat extension. You can use any command typically available on the windows command prompt (AKA cmd.exe ). A good starting point is learning how to move and copy files around so you want to take a look at the commands by the same name on the Command-line reference from Microsoft . There is also a handy guide linked on the same page to batch files and how they work .

The documentation linked is for Widows XP and the syntax of the commands should be back and forwards compatible with other Windows versions.

This code is a simple batch script. Customize this code.

Code:

@echo off
color f0
:: overwrite your program name after the '=' ::
set ProgramNameHere=ProgramNameHere
goto start
:start
cd/
cd users
cd %username%
cd desktop
md %ProgramNameHere%
:: overwrite your file path on the 'DATA' ::
:: overwrite your file name on the 'file1', 'file2'...
:: overwritw your file name after the 'extracting'.
echo DATA>>C:\Users\%Username%\Desktop\%programNameHere%\file1.txt
echo extracting file 1
ping localhost>nul
echo DATA>>C:\Users\%Username%\Desktop\%programNameHere%\file2.txt
echo extracting file 2
ping localhost>nul
echo DATA>>C:\Users\%Username%\Desktop\%programNameHere%\file3.txt
echo extracting file 3
ping localhost>nul
echo DATA>>C:\Users\%Username%\Desktop\%programNameHere%\file4.txt
echo extracting file 4
ping localhost>nul
echo DATA>>C:\Users\%Username%\Desktop\%programNameHere%\file5.txt
echo extracting file 5
ping localhost>nul
echo DATA>>C:\Users\%Username%\Desktop\%programNameHere%\file6.txt
echo extracting file 6
ping localhost>nul
echo DATA>>C:\Users\%Username%\Desktop\%programNameHere%\file7.txt
echo extracting file 7
ping localhost>nul
echo DATA>>C:\Users\%Username%\Desktop\%programNameHere%\file8.txt
echo extracting file 8
ping localhost>nul
echo DATA>>C:\Users\%Username%\Desktop\%programNameHere%\file9.txt
echo extracting file 9
ping localhost>nul
echo DATA>>C:\Users\%Username%\Desktop\%programNameHere%\file10.txt
echo extracting file 10
ping localhost>nul
goto exit

:exit
exit

Installing a Java program is the same thing as installing a ... program ;-) You can create a batch installer from scratch with a .bat file or use an installer builder tool. I use NSIS because it's free and simple to use ... but there's others.

You also may want to build an .exe instead of a jar file (sometime, windows open the jar archives instead of launching java). I use Launch4J to wrap my java application in a .exe file.

If the app. has a GUI, install/launch it using Java Web Start . It works on Windows, OS X & *nix, and can install both desktop shortcuts and menu items to launch the app. on platforms that support such things.

JWS is supported & supplied by Oracle.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM