Minggu, 01 Desember 2013

BATCH NOTEPAD JILID 1.


SCRIPT : THUNDER VOLTAGER) (TV)
Disini kami mencoba untuk mengulas secara sederhana agar secara umum garis besar nya dapat dicerna, tapi bila anda telah menguasainya maka silahkan ikuti  %,@x$#.......
Jangan di gunakan untuk merugikan orang lain , tapi manfaatkan ilmunya agar barokah. Pelajari cara kerjanya dan buat obatnya untuk menolong / buat scipt yang bermanfaat.
Kunci dari Semua Script ini adalah ditulis di dalam NOTEPAD.
Pertama Buka Notepad anda :
Click kanan mouse button dan pilih Text Document / Buka Notepad. Atau Cara lain
Tekan Start + R >tulis Notepad > tekan Enter. Masih banyak cara lain untuk ini.

===========================================================================

Batch adalah:
salah satu bahasa scripting yang paling mudah dan didasarkan pada MS-DOS yang kebanyakan orang tidak mengtahui bahwa sebenarnya MS-DOS bukan program tetapi hanya sekedar sesuatu pada komputer sebagai OS atau pengopersian System..
Sistem operasi ini sebenarnya lebih kuat daripada MS-DOS yang Anda gunakan untuk windows Sistem operasi.
Kita sekarang menjalankan MS-DOS di bawah windows karena yang baik memang berjalan di bawah Windows ..
Di masa lalu mereka tidak memiliki GUI atau Graphical User Interface. Jadi semua yang mereka lakukan harus menggunakan DOS.
DOS adalah singkatan dari Disk Operating System.
____________________________________________________________________________

Bagaimana memulai sebuah file batch
Untuk membuat file batch yang harus Anda lakukan adalah hanya membuat nya di notepad
Setelah Anda masukkan kodenya dan kemudian simpan "Save As.bat" (tanpa tanda kutip tentunya). Sebagai contoh: dataku.bat
Kebanyakan orang yang menggunakan batch , selalu mematikan  echo maksudnya agar tidak akan memunculkan kode.
Caranya adalah dengan menuliskan code seperti dibawah ini :

@echo off
Sekarang perhatikan beberapa Perintah Dasar berikut ini.
echo,
copy,
del,
deltree,
end.
Echo - Menampilkan teks yang tertulis setelah "echo" misalnya:
Echo "Hello, mari kita belajar tutorial"
Copy - Untuk menyalin file batch ke direktori tertentu, misalnya:
Copy C:\Program Files\new folder
Del - deletes certain file, for example
Del C:\Program Files\new folder >
Deltree - Menghapus tree dari file dalam direktori tertentu, misalnya:

Deltree C:\Program Files\new folder

End - mengakhiri script misalnya:

End
Start -Memulai .exe (program) misalnya: memulai membuka notepad
Start norepad
(atau jika tidak berhasi dalam program)start C:\ProgramFiles\new game.exe

Sekarang mari kita lihat bagaimana ketika semua nya digabungkan.

@echo off
Echo "Hello, mari kita belajar tutorial"
Copy C:\Program Files\new folder
Del C:\Program Files\new folder
Deltree C:\Program Files\new folder1
Start notepad
End
____________________________________________________________________________
Pause
Menunda proses batch, Biasanya di ikuti box pesan , "Press any key to continue..." User bisa tekan tombol apapun untuk melanjutkan ;

Silahkan coba yang satu ini

@echo off
echo hello Saya ke 1.
pause
echo hello Saya ke 2.
pause
echo hello Dibawah saya kosong
echo.
echo Jelas kosong karena ada titik di echo
echo OH, begitu yach
pause
Save sebagai .bat extension. type All file
Untuk tulisan " @echo off " dapat dihilangkan dan coba sendiri apa bedanya..
Coba juga apa yang terjadi bila Pause terakhir dihilangkan.
. . . . . . . agar anda lebih tahu dan pintertrt.
. . . . . . . Tapi menurut saya sebaiknya gunakan Pause>null ____________________________________________________________________________
Msg
Msg >Mengirim pesan popup ke TS User / User tertentu.
Msg * >Mengirim pesan ke semua User pada sistem

Silahkan coba yang satu ini

msg * Error: Ada Virus

ATAU YANG INI

@echo off
msg * Semakin banyak orang pinter
msg * Semakin banyak virus notepad
Save sebagai .bat extension. type All file Untuk - msg * - Bisa dituliskan sebanyak mungkin.

____________________________________________________________________________
Menggunakan Echo dan Msg

@echo off
echo 1. Coba lakukan seperti ini
pause
echo 2. Kita sedang coba-coba
pause
echo 3. Dalam hitungan mundur
pause
echo T i g a
pause
echo D u a
pause
echo S a t u
pause
echo Go go go go
msg * Jangan tekan enter Ulang lagi
msg * T i g a
msg * D u a
msg * S a t u
msg * Go go go go
Save sebagai .bat extension. type All file Selanjutnya sampai dasar disini dapat anda kembangkan sendiri.

11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111

===========================================================================
Dasar Penggunaan Perintah Batch File

____________________________________________________________________________
Catatan:
Setiap perintah DOS dapat digunakan dalam file batch, di bawah ini adalah daftar perintah yang digunakan untuk mendukung structure dan flow dari batch file*

Anda dapat membuat batch file yang mampu menerima operand pada saat di jalankan.
Untuk keperluan ini di pakai parameter dummy yaitu %0 , %1, %2, %3, …, %8, %9.
Misalkan Anda ingin membuat batch file yang apabila di jalankan akan menampilkan directory dari suatu file tertentu yang di sebutkan di awal pelaksanaan batch file

Commands yang dapat dipakai pada Batch File :
• CLS, menghapus perintah pada layar .
• Call, memanggil satu batch program tanpa menghentikan induk batch program ;
• Echo, mengkatifkan fitur perintah pengumandangan atau menampilkan pesan ;
• For, menjalankan perintah yang ditentukan untuk setiap file dalam satu set file ;
• Goto, mengarahkan Windows ke baris yang diidentifikasi oleh label/penanda ;
• If, melakukan pemrosesan kondisional dalam batch program ;
• Pause, menunda proses batch, user bisa tekan tombol apapun untuk melanjutkan ;
• Shift, mengubah posisi parameter batch dalam sebuah batch file .
• Start, untuk menjalankan suatu aplikasi dalam jendela terpisah.

____________________________________________________________________________
@
Letakan @ di depan perintah yang Anda tidak ingin ditampilkan dalam proses.


BREAK ON/OFF
Ketika mengaktifkan file batch, user memiliki pilihan untuk menghentikan file batch dengan menekan CTRL+C
DOS systems.tidak berpengaruh pada Windows 2000.


CALL
Memanggil satu bagian batch program tanpa menghentikan induk batch program ;
Memanggil file batch lain. Setelah file batch selesai, Control dikembalikan ke pertama
Contoh :

CALL c:\Windows\Newbat.bat
Tempatkan line di autoexec.bat Anda yang digunakan setiap saat Anda memanggil / ingin boot komputer. Sebagai contoh:

CALL C:\myboot.bat

CLS
Membersihkan layar dari data sebelumnya
menghapus perintah pada layar , berfungsi untuk membersihkan tampilan layar
CLS membersihkan jendela perintah saat ini sehingga hanya menunjukkan prompt.
contoh :

dir d: @echo off
echo tekan sembarang tombol untuk membersihkan echo.
pause>nul
cls
pause>nul

ECHO.
mengkatifkan fitur perintah pengumandangan atau menampilkan pesan ;
Tidak hanya dapat mematikan tampilan perintah,
Tetapi juga dapat menampilkan apapun yang ditulis setelah itu.
Jika kita menempatkan spasi setelah perintah ECHO, maka akan mencetak apa pun yang Anda ketik pada command window.
Jika Anda menempatkan . (titik2) setelah ECHO maka Perintah itu akan membentuk garis.

ECHO ...............................................
ECHO Tuliskan Text di sini untuk di munculkan dalam box
ECHO ...............................................
Cara membuat baris kosong dalam file batch.Apa yang Anda lakukan adalah menulis Echo tetapi pada akhir Echo menempatkan period misalnya:

Echo.
Contoh berikut adalah sebuah program batch yang dilengkapi pesan tiga baris.
didahului oleh baris kosong dan kemudian diakhiri dengan baris kosong pula.

echo off
echo Menulis di perintah Echo
echo.
echo Kalau ada titik maka echo akan kosong
echo Moga berhasil
echo.
Jika Anda ingin mengubah echo off dan Anda tidak ingin menampilkan perintah echo,
ketik tanda (@) sebelum perintah seprti berikut:

@echo off
Anda dapat menggunakan if dan perintah echo pada baris perintah yang sama.
Sebagai contoh:

if exist *.rpt echo Semuanya berjalan lancar
ECHO OFF berfungsi untuk meniadakan tampilan prompt dan perintah di layar.
Tulisan "ECHO OFF"-nya sendiri tetap di tampilkan,
ECHO ON berfungsi untuk menampilkan prompt dan perintah di layar.


ECHO ON
Biasanya penampilan ditambahkan ; @

(@ECHO ON).
ECHO ON

ECHO OFF
Biasanya penampilan ditambahkan ; @
(@ECHO OFF).
berfungsi untuk meniadakan tampilan prompt dan perintah di layar.
Tulisan "ECHO OFF"-nya sendiri tetap di tampilkan,
Sedangkan "ECHO ON" berfungsi untuk menampilkan prompt dan perintah di layar.

contoh :

ECHO OFF
CLS
Rem Gampang tapi susah
Rem Susah tapi gampang
Dir A:
ECHO OFF
hanya menyembunyikan perintah berikutnya,
jika Anda ingin menyembunyikan semua perintah maka harus
menggunakan  @ ECHO OFF.
Setelah dimatikan tampilan baris berikutnya, tetapi kemudian kita akan mengeluarkan lagi maka kita harus menggunakan perintah


END
Mengakhiri suatu process.


FOR
menjalankan perintah yang ditentukan untuk setiap file dalam satu set file ;
Perintah FOR di gunakan untuk mengulang - ulang pelaksanaan perintah DOS.
contoh:

FOR %%bb IN (COMMAND.COM FORMAT.COM) DO DIR %%bb
Bila di terjemahkan Sama saja dengan perintah dibawah ini :

DIR A:COMMAND.COM
DIR A:FORMAT.COM

GOTO
mengarahkan Windows ke baris yang diidentifikasi oleh label/penanda ;
Perintah GOTO di gunakan untuk mengalihkan pelaksanaan batch file ke baris tertentu yang di awali oleh suatu label.

GOTO
Ini digunakan untuk perintah melanjutkan / pergi ke section lain.

:FirstSection
REM Welcome to the first section
GOTO :SecondSection
:SecondSection
REM Welcome to the second section
GOTO :End
:END

IF
Melakukan pemrosesan kondisional dalam batch program ;
Perintah IF di gunakan untuk melaksanakan suatu perintah DOS tertentu berdasarkan kondisi yang mengikutinya.

echo off
color 0d
:awal
echo.
echo pilih angka 1 - 3
echo.
set /p "bat=pilih angka ! .. "
if %bat%=='' goto awal
if %bat%==1 shutdown -s -t 12
if %bat%==2 shutdown -l
if %bat%==3 shutdown -a
pause>null
echo off
color 0d :awal echo. echo pilih angka 1 - 3 echo. set /p "bat=pilih angka ! .. "
if %bat%=='' goto awal
if %bat%==1 shutdown -s -t 12
if %bat%==2 shutdown -l
if %bat%==3 shutdown -a
pause>null

LABEL
di pakai untuk menandai suatu baris tertentu di dalam suatu batch file.
Penulisan suatu label harus di dahului oleh tanda titik dua ( : ).

contoh:

@echo off
color a
:top
echo %random%
goto top
Hal ini memungkinkan untuk mengulang-ulang dengan perintah GOTO:

:Start
REM No!!!!!!!!!!!!!!!!!! It's Looping !!!!!!!!!!!!!
GOTO :Start

LOOP
menggambarkan proses program atau script mengulangi instruksi yang sama atau memproses informasi yang sama berulang-ulang sampai menerima perintah untuk berhenti.
Jika tidak ditangani dengan baik loop dapat menyebabkan komputer menjadi lambat karena menjadi kewalahan dengan beban harus mengulangi langkah yang sama berulang menyebabkan ia terjebak dalam lingkaran tak berujung.

Di bawah ini adalah dasar script.

:Begin
Echo Ini akan berputar-putar tanpa berhenti atau loop! sehingga disebut endless loop
Goto Begin
Endless loop
Seperti digambarkan dalam contoh di atas, program akan mencetak endless loop,
Perintah akan kembali ke Begin dan terus akan mengulangi lagi proses ini tanpa batas.


MENU
Membuat Menu
Sekarang kita akan mencoba membuat menu.
Ini akan menjadi teks yang tampil ketika kita membuka file batch dan juga akan mengeksekusi perintah lainnya sebelum keluar.


MSG
Msg Mengirim pesan popup ke TS User / User tertentu.
Msg * Mengirim pesan ke semua User pada sistem
msg * Error: Ada Virus

ATAU YANG INI

@echo off
msg * Semakin banyak orang pinter
msg * Semakin banyak virus notepad

PAUSE
Menunda proses batch, Biasanya di ikuti box pesan , "Press any key to continue..."
User bisa tekan tombol apapun untuk melanjutkan ;
Perintah PAUSE berfungsi untuk  menghentikan proses pelaksanaan batch file, sambil menunggu penekanan sembarang tombol keyboard oleh pemakai.
Pelaksanaan perintah PAUSE akan menghasilkan pesan ; Strike any key when ready ...

Contoh :
@echo off
echo hello Saya ke 1.
pause
echo hello Saya ke 2.
pause
echo hello Dibawah saya kosong
echo.
echo Jelas kosong karena ada titik di echo
echo OH, begitu yach
pause

REM
Memungkinkan untuk menempatkan  komentar , menampilkan pesan ke pengguna
(Misalnya  Rem HELLO!).

Perintah REM
REM singkatan dari REMark, artinya catatan. Kata - kata yang berada di sebelah kanan perintah ini tidak untuk di kerjakan tetapi untuk ditampilkan.

@echo on
rem pesan ini untuk pengguna
rem .......
pause
rem muncul pesan peringatan
rem ......
pause>null
rem pesan peringatan tidak akan dimunculkan
rem .......
pause>null
Perhatikan perbedaannya dengan MSG diatas..?
Beberapa orang menggunakan :: yang secara teknis termasuk label..
Tetapi rupanya menggunakan :: dapat mengakibatkan eksekusi script lebih cepat (ini hanya pendapat beberapa orang).
Contoh Rem This batch file uses characters like >,...
Diganti dengan :: This batch file uses characters like >,...

REM adalah perintah yang benar yang dapat digunakan di mana saja dalam baris perintah. Meskipun aku ragu ada banyak digunakan untuk perintah seperti:
IF EXIST C:\AUTOEXEC.BAT REM AUTOEXEC.BAT exists
http://www.robvanderwoude.com/comments.php

Shift,
mengubah posisi parameter batch dalam sebuah batch file .


Start,
untuk menjalankan suatu aplikasi dalam jendela terpisah.

http://www.robvanderwoude.com/termserv.php#ChgPort

22222222222222222222222222222222222222222222222222222222222222222222222222222222222

===========================================================================
Disini anda tidak perlu cerewet karena saya juga dapat dari CopyPaste . . ! !

@ In DOS version 3.3 and later, hides the echo of a batch command. Any output generated by the command is echoed. The at-sign can be prefixed to any DOS command, program name, or batch file name within a batch file.

@[command]
    examples @ {Seperates sections of the batch file without diplaying the DOS prompt.}

@echo OFF {Hides the echo off report.}
%DIGIT Replaceable batch parameters which are defined by the user when the batch is executed. The parameters are separated by spaces, commas, or semicolons.

%digit {Digit: any digit from 0 to 9. %0 has the value of the batch command as it appears on the command line when the batch is executed. %1 represents the first string typed after the batch commmand. Each occurrence of %digit is replaced by the corresponding string from the batch command line.}
    examples MYBATCH DOC A:
COPY *.%1 %2
{Copies all .DOC files in the default directory to drive A:}
%VARIABLE% Replaces the DOS environment variable name with its environment value.

%variable% {Variable: a string of uppercase characers in the environment associated with a string value. Variable is created in the environment by using SET.}
    examples %PATH% {Returns the value of PATH, the current search path, which is executable.}

echo %PATH% {Displays the value of PATH, the current search path.}

%PROMPT% {Returns the value of PROMPT, the current prompt string, which is executable.}

echo %PROMPT% {Displays the value of PROMPT, the current prompt string.}

echo The current search path is: %PATH% {Displays the message including the current search path.}

set USER=John
if %USER%= =John goto LABEL
{Since the value of USER does equal "John", the control is transferred to the label, LABEL.}
CALL Loads and executes a batch file from within a batch file as if it were a external command. When a second batch file completes, control is returned to the calling file.

call [drive:][path]filename [batch-parameters]
Before DOS version 3.3:
command /c [drive:][path]filename [batch-parameters]
CLS Clears the video display screen, setting the cursor in the upper left-hand corner.

cls
ECHO Controls whether commands and comments within a batch file are displayed.

echo [ON|OFF|message|.]
    examples echo {Displays echo status}

echo ON {Restores normal display activity.}

echo OFF {Halts display of DOS prompt and commands.}

echo Processing... {Displays "Processing..." on the screen.}

echo %USER% {Displays the value of USER on the screen.}

echo. {Displays a single blank line on the screen.}

echo ^L > prn {Sends an ASCII control-code (form feed) to the printer. Press <Ctrl> plus <L> to type the ^L character.}

echo Y|Del *.* {Answers the DEL "Are you sure" question automatically.}
FOR Repeats the operation of a DOS command for each member of a list. Use CALL to execute a batch file as a command.

for %%argument in (list) do command {Argument: any letter from A to Z. List: a sequence of strings separated by spaces or commas. Wildcards are allowed.}
    examples for %%d in (A,C,D) do DIR %%d *.* {Displays the directories of drives A, C, and D sequentially.}

for %%f in (*.TXT *.BAT *.DOC) do TYPE %%f {Types the contents of all .TXT, .BAT, and .DOC files in the current default directory.}

for %%P in (%PATH%) do if exist %%P\*.BAT COPY %%P\*.BAT C:\BAT {Copies all batch files which exist in any directory on the DOS command search path into the directory C:\BAT.}

for %%f in (*.PAS) do call compile %%f {Compiles all .PAS files in the current default directory.}
GOTO Transfers control within a batch file to a line identified by a label. The label must be of the form ":LABEL".

goto LABEL
:LABEL
IF Tests a condition and executes a command only if the condition is TRUE. But if the NOT modifier is present, the command will be executed only if the condition is FALSE.

if [not] condition command {Condition: errorlevel number; string1= =string2; or exist filename. Command: any DOS command, batch command, batch file name, or program name.}
    examples if [not] errorlevel number command {Errorlevel: an exit code returned by a program or an external command. The following DOS commands return an exit code: BACKUP, RESTORE, FORMAT, REPLACE, and XCOPY. Number: a numerical value (integer) against which the exit code is compared. The condition is TRUE if the exit code returned by the previous program is greater than or equal to number. The condition is FALSE if the exit code is less than number.}

BACKUP C:\*.* A: /s
if errorlevel 3 goto TROUBLE
{If the BACKUP command exits with a code of 3 or higher, control will be transferred to the label TROUBLE.}

if errorlevel 3 if not errorlevel 4 echo ERROR #3 occurred
if errorlevel 4 if not errorlevel 5 echo ERROR #4 occurred
{Nested if statements that determine the exact error number.}

if [not] string1= =string2 command {The condition is TRUE if both strings are identical. The comparison is case sensitive. If either string is blank, a syntax error occurs.}

if (%1)= =(LTRS) CD C:\WORD\LTRS {If the first parameter is LTRS, the change directory to LTRS.}

if "%1"= ="" goto ERROR {If there is no parameter, then control is transferred to label ERROR.}

if not %2X= =X DIR %2\*.* {If there is a second parameter, then display all the files contained in the directory %2.}

if not "%3"= ="" if not "%3"= ="b" if not "%3"= ="B" goto BADPARAM {If there is no third parameter or if it is anything other than b or B, then go to label BADPARAM.}

if [not] exist filename command {The condition is TRUE if filename can be located. The filename can include drive and path specifications. Wildcards are allowed.}

if exist D:\%1\nul CD %1 {Tests for the existence of directory %1 even if it contains no files, then changes to that directory if it exists.}

if not exist A:\FLASH.EXE COPY C:\PROJECTS\FLASH.EXE A: {Copies FLASH.EXE to drive A, but only if it doesn't exit there already.}
PAUSE Pauses the running of a batch file and displays the message "Press any key to continue ..." on the screen. If the optional message is included, it will be displayed first. Use pause to optionally terminate the batch file with <Ctrl-Break> at a safe place. The optional message is not displayed when echo is OFF, so the message must be echoed on the preceding line.

pause [message]
    examples pause {Displays "Press any key to continue ...".}

pause < nul {Waits with no comment.}

pause Do you want to continue? {Displays "Do you want to continue?" with "Press any key to continue ..." on the next line.}
REM Adds remarks to a batch file.

rem [remark]
    examples @rem {Hides the remark from display.}
SET Set will view the DOS environment or create, change, or delete environment values.

set [variable=[value]] {Variable: a string of characters, unbroken by spaces, which are converted to uppercase letters in the environment. Value: a string of characters, case specific, associated with variable.}
    examples set {Display the entire DOS environment.}

set USER=John {Sets the value of USER to the string, "John".}

set USER= {Removes USER from the environment.}

set PATH=C:\;C:\DOS {Sets C:\;C:\DOS as the current search path.}

set PATH=%PATH%;C:\TEST {Appends ;C:\TEST to the current search path.}
SHIFT Shifts any parameter on the command line one position to the left. Use SHIFT to refer to multiple parameters by one name or to use more than ten parameters on a single command line.

shift
    examples :LOOP
COPY %1 A:
shift
if not (%1)==() goto LOOP
{Beginning with the first parameter, all the parameters listed on the command line are iterated and a file, the value of the parameter, is copied to A:.}
Miscellaneous

command > nul {Redirects command output to oblivion.}

command > file {Redirects command output to file.}

command >> file {Appends command output to file.}

command < file {Redirects file output to command.}

PATH {Displays "PATH=" followed by the value of PATH, the current search path.}

PATH directories {Sets directories as the current search path.}

PATH = directories {Sets directories as the current search path.}

PATH; {Disables extended command searching and confines the searching to the default directory.}

PROMPT {Resets the prompt string to its default, $n$g.}

CD {Displays the current directory and its path.}

. {Represents the default directory (If PATH=D:\;C:\SYS;C:. then current directory will be searched after D: and C:\SYS).}

.. {Represents the parent of the default directory (C:\TOOLS\WP\LTRS.DOC is the same as ..\WP\LTRS.DOC).}

%% {A literal "%".}
===========================================================================

Tidak ada komentar:

Posting Komentar