Friday, August 21, 2026

How to open notepad and type with batch file

 @echo off

title Type Text Automation


:: 1. Open Notepad

start "" notepad.exe

echo Waiting for Notepad to open...

timeout /t 2 >nul


:: 2. Create a temporary script to type text

set "VBS_FILE=%temp%\type_text.vbs"


(

echo Set objShell = WScript.CreateObject^("WScript.Shell"^)

echo ' Make sure Notepad is the active window

echo objShell.AppActivate "Notepad"

echo WScript.Sleep 500

echo ' Type the characters

echo objShell.SendKeys "abcd"

) > "%VBS_FILE%"


:: 3. Execute the typing script

cscript //nologo "%VBS_FILE%"


:: 4. Delete the temporary script file

del "%VBS_FILE%"


echo Done!

timeout /t 2 >nul


How to create notepad file with batch file

 @echo off

title Text Steps Recorder

cls

echo ==========================================

echo TYPE YOUR STEPS BELOW (Press Enter after each line)

echo Type "EXIT" and press Enter when finished.

echo ==========================================

echo.


:loop

set /p userinput="Enter text/step: "

if "%userinput%"=="EXIT" goto end

if "%userinput%"=="exit" goto end


:: This saves what you typed into a file called keystrokes.txt

echo %userinput% >> keystrokes.txt

goto loop


:end

echo.

echo Recording saved to keystrokes.txt!

pause


How to copy txt file from notepad to new notepad using bat file - batch file

 @echo off

title Steps Replayer

cls

echo Ready to replay steps. 

echo You have 5 seconds to click inside the app where you want to type!

echo.

timeout /t 5


:: This block creates a temporary script to simulate automated typing

echo Set wshShell = wscript.CreateObject("WScript.Shell") > replay.vbs


:: This reads your saved text file and writes it into the automated typer

for /f "delims=" %%x in (portalchanges.txt) do (

    echo wshShell.SendKeys "%%x" >> replay.vbs

    echo wscript.sleep 500 >> replay.vbs

    echo wshShell.SendKeys "{ENTER}" >> replay.vbs

    echo wscript.sleep 500 >> replay.vbs

)


:: This runs the automatic typing script and then deletes the temporary file

cscript //nologo replay.vbs

del replay.vbs


echo.

echo Replay complete!

pause


Thursday, August 20, 2026

How to take backup of MSQL database - MYsql database backup by bat file or by batch file

 C:\Program Files\MySQL\MySQL Workbench 8.0 CE>mysqldump -u root -p  eoffice_db documents >d:/backup_filename.sql


@echo off

:: Configuration

set DB_USER=root

set DB_PASS=12345

set DB_NAME=eoffice_DB

set BACKUP_DIR=C:\eoffice_DB\documents


:: 1. SET YOUR TABLE NAME HERE

:: Leave blank for full DB, or type a single table (e.g., users)

set TABLE_NAME=documents


:: Get Date Format safely (YYYYMMDD) regardless of Windows regional settings

for /f "tokens=2 delims==" %%i in ('wmic os get localdatetime /value') do set LDT=%%i

set BACKUP_DATE=%LDT:~0,4%%LDT:~4,2%%LDT:~6,2%


:: Adjust file name based on whether a table is specified

if "%TABLE_NAME%"=="" (

    set BACKUP_FILE=%BACKUP_DIR%\%DB_NAME%_%BACKUP_DATE%.sql

) else (

    set BACKUP_FILE=%BACKUP_DIR%\%DB_NAME%_%TABLE_NAME%_%BACKUP_DATE%.sql

)


:: Ensure target directory exists

if not exist "%BACKUP_DIR%" mkdir "%BACKUP_DIR%"


:: Execute mysqldump

"C:\Program Files\MySQL\MySQL Workbench 8.0 CE\mysqldump.exe" -u%DB_USER% -p%DB_PASS% %DB_NAME% %TABLE_NAME% > "%BACKUP_FILE%"


:: Optional: Delete files older than 30 days

forfiles /p "%BACKUP_DIR%" /s /m *.sql /d -30 /c "cmd /c del @path"