Skip to content

Structural improvements on scripts #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Auto detect text files and perform LF normalization
* text=auto

# This tells Git that never replace CRLF with LF for `.bat` files when
# they are written to the Git object database ("checkin").
*.bat -text
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Windows image file caches
Thumbs.db
ehthumbs.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msm
*.msp
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

27 changes: 0 additions & 27 deletions README

This file was deleted.

29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<h1 align="center">Batch Script Utils</h1>

### Important Notice

Here is some more detailed information about the scripts I have written. I do not consider myself a programmer, I create these little programs as experiments to have a play with the language, or to solve a problem for myself. I would gladly accept pointers from others to improve the code and make it more efficient, or simplify the code. If you would like to make any comments then please feel free to email me at [[email protected]](mailto:[email protected]).

In the scripts the comments etc are lined up correctly when they are viewed in [Notepad++](https://notepad-plus-plus.org/). This is what I use to code [batch scripts](https://en.wikipedia.org/wiki/Batch_file).

### Scripts in the repository

| Script | Description | Usage |
|:------:|-------------|:-----:|
| defragment.bat | This script is used to schedule a defragmentation of the Windows platform. | `defragment.bat` |
| doskey.bat | This script demonstrates how to use aliases on the command line. | `doskey.bat` |
| iTunes.bat | This script backs up the iTunes library on an external drive. | `iTunes.bat` |
| lockPC.bat | This script is used to lock the computer easily. | `lockPC.bat` |
| logOff.bat | This script terminates the session on the PC. | `logOff.bat` |
| openCMD.bat | This script opens a new CMD window. | `openCMD.bat` |
| puttyBackup.bat | This script backs up all your PuTTY sessions to a .reg file. | `puttyBackup.bat` |
| startup.bat | This script allows some services and programs to start automatically. | `startup.bat` |
| whereis.bat | This script shows the path of a program. | `whereis.bat <program name>` |

### Supporters

<p align="center">
<a href="https://badges.pufler.dev/contributors/geekcomputers/Batch?size=50&padding=5&bots=true">
<img src="https://badges.pufler.dev/contributors/geekcomputers/Batch?size=50&padding=5&bots=true" alt="Contributing"/>
</a>
</p>
14 changes: 0 additions & 14 deletions cmd.bat

This file was deleted.

14 changes: 0 additions & 14 deletions defrag.cmd

This file was deleted.

41 changes: 41 additions & 0 deletions defragment.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
:: ===========================================================================================================
:: @file defragment.bat
:: @brief The batch file I used to use to schedule a defrag of the c:\, using the AT command
:: @update 27.05.2022
:: @version 1.1
:: @usage defragment.bat
:: @see https://github.com/sebetci/Batch-Script-Basics/blob/master/defragment.bat
:: @reference https://ss64.com/nt/defrag.html
:: @note This script must be run in a command window with administrator rights.
:: @test OK
:: @todo Log file must be passed as a parameter from the command line.
:: @todo The existence of drivers should be checked.
:: ===========================================================================================================

@ECHO OFF

:: The HELP function is called.
CALL :HELP

IF %ERRORLEVEL% EQU 0 (
:: Defragment hard drive volumes.
DEFRAG C: >> C:\Defragment.log
)

GOTO :EOF

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: @function This function prints the help menu on the screen.
:: @parameter None
:: @return Returns 1 if the help menu is displayed.
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:HELP
FOR %%H IN (/h /help -help -h) DO (
IF /I "%~1" EQU "%%~H" (
ECHO.
ECHO [BRIEF] The batch file I used to use to schedule a defrag of the c:\, using the AT command
ECHO [USAGE] defragment.bat
EXIT /B 1
)
)
EXIT /B 0
94 changes: 94 additions & 0 deletions doskey.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
:: ===========================================================================================================
:: @file doskey.bat
:: @brief Recall and edit commands at the DOS prompt, and create macros.
:: @update 27.05.2022
:: @version 1.1
:: @version 1.7
:: @description Create Aliases for DOS screen
:: @usage doskey.bat
:: @see https://github.com/sebetci/Batch-Script-Basics/blob/master/doskey.bat
:: @reference https://ss64.com/nt/doskey.html
:: @reference https://docs.microsoft.com/en-us/windows-hardware/drivers/other-wdk-downloads
:: @reference https://github.com/geekcomputers/Batch/issues/5
:: @changelog 1.2. Added enable_wireless and disable_wireless
:: @changelog 1.3. Added history alias so I can show the history for the session
:: @changelog 1.4. Added a link to the whereis command file to use the utility
:: @changelog 1.5. Added an alias to start and stop mysql server on notebook, and a shortcut to mysql, may remove and add it to my path
:: @changelog 1.6. Totally changed the script, it now checks that if it running on my netbook, it sets a certain subset of aliases, if any other machine it just creates the generic aliases
:: @changelog 1.7. Added alias for SQLITE
:: @note The use of DOSKEY command in batch script files (*.cmd, *.bat) is not allowed.
:: @test OK
:: @todo How to transfer special system variables to the global path should be investigated.
:: @todo The existence of files and directories should be checked.
:: ===========================================================================================================

@ECHO OFF

CALL :HELP

IF %ERRORLEVEL% EQU 0 (
:: If the variable %ComputerName% is GEEKBOOK, the SPECIFIC function is called.
IF %ComputerName% EQU GEEKBOOK ( CALL :SPECIFIC ) ELSE ( CALL :GENERIC )
)

GOTO :EOF

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: @function This function contains alias definitions that can work on any system.
:: @parameter None
:: @return None
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:GENERIC
:: Display a list of files and subfolders.
DOSKEY LS=DIR

:: Clear the screen.
DOSKEY CLEAR=CLS

:: Edit command line, recall commands, and create macros
DOSKEY HISTORY=DOSKEY /h

:: The whereis.bat script included in this repo is called.
:: The variable %scripts% represents the directory where this repository is located.
DOSKEY WHEREIS="%scripts%"\whereis.bat $*

:: The following alias can be used to open a database file.
DOSKEY SQLITE=SQLITE3 "%dropbox%"\Databases\sampleDatabase.db

:: On Windows systems, the %HOMEDRIVE% variable changes to the C:\ directory.
CD /D %HOMEDRIVE%
EXIT /B 0

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: @function Some tools (MYSQL, DEVCON.EXE) must be installed on your system for this function to work.
:: @parameter None
:: @return None
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:SPECIFIC
:: If MySQL 5.6 is installed on your system, the name of the service will be MYSQL56.
DOSKEY START_MYSQL=NET START MYSQL56
DOSKEY STOP_MYSQL=NET STOP MYSQL56
DOSKEY MYSQL="C:\Program Files\MySQL\MySQL Server 5.6\bin\mysql"

:: The Windows Driver Kit (WDK) installation is required to use the DEVCON.EXE program.
DOSKEY ENABLE_WIRELESS=DEVCON ENABLE *DEV_001C*
DOSKEY DISABLE_WIRELESS=DEVCON DISABLE *DEV_001C*

GOTO :GENERIC
EXIT /B 0

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: @function This function prints the help menu on the screen.
:: @parameter None
:: @return Returns 1 if the help menu is displayed.
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:HELP
FOR %%H IN (/h /help -help -h) DO (
IF /I "%~1" EQU "%%~H" (
ECHO.
ECHO [BRIEF] Recall and edit commands at the DOS prompt, and create macros.
ECHO [USAGE] doskey.bat
EXIT /B 1
)
)
EXIT /B 0
44 changes: 0 additions & 44 deletions doskey.cmd

This file was deleted.

57 changes: 57 additions & 0 deletions iTunes.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
:: ===========================================================================================================
:: @file iTunes.bat
:: @brief Batch file I used to use to backup my iTunes library on my pc, scheduled via the at command
:: @update 27.05.2022
:: @version 1.1
:: @usage iTunes.bat
:: @see https://github.com/sebetci/Batch-Script-Basics/blob/master/iTunes.bat
:: @reference https://samsoft.org.uk/iTunes/scripts.asp
:: @reference https://ss64.com/nt/move.html
:: @reference https://ss64.com/nt/md.html
:: @reference https://ss64.com/nt/xcopy.html
:: @test X
:: @todo Log file must be passed as a parameter from the command line.
:: @todo For a portable script, the file and directory structure should be arranged.
:: ===========================================================================================================

@ECHO OFF

CALL :HELP

IF %ERRORLEVEL% EQU 0 (
:: The following command writes the current date to the C:\iTunes.log file using the %DATE% environment variable.
ECHO %DATE% >> C:\iTunes.log

:: If the G:\iTunes\ directory exists
IF EXIST G:\iTunes\
:: Move a file from one folder to another.
MOVE /Y G:\iTunes G:\iTunes.%DATE%

:: Make directory
MD G:\iTunes\

:: Copy files and/or directory trees to another folder.
XCOPY /Y /S C:\DOCUME~1\CRAIGR~1\mydocu~1\mymusi~1\iTunes\* G:\iTunes >> C:\iTunes.log

:: Copy files and/or directory trees to another folder.
XCOPY /Y /S F:\iTunes\* G:\iTunes >> C:\iTunes.log
)

GOTO :EOF


::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: @function This function prints the help menu on the screen.
:: @parameter None
:: @return Returns 1 if the help menu is displayed.
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:HELP
FOR %%H IN (/h /help -help -h) DO (
IF /I "%~1" EQU "%%~H" (
ECHO.
ECHO [BRIEF] Batch file I used to use to backup my iTunes library on my pc, scheduled via the at command
ECHO [USAGE] iTunes.bat
EXIT /B 1
)
)
EXIT /B 0
18 changes: 0 additions & 18 deletions itunes.cmd

This file was deleted.

Loading