Welcome, guest | Sign In | My Account | Store | Cart

This is a Batch Local Messaging System that can be used to send messages between computers that share the same file system.

There are three files in the code below. They are separated with dashed lines. There is a comment on the top of each segment of code indicating the file name that the code needs to be saved as. They need to be saved as three separate batch files in the same folder.

The first file, MessengerMain.bat will ask you for your name and then an address. The name should be whatever you wish your screen name to be. The address needs to be the path of the FOLDER that is shared between you and the other computer that you are communicating with. Once these pieces of information are entered, two screens will appear. The first is the Sender screen and the other is the Receiver screen.

How does it work? The MessengerMain.bat file will create two text files, Name.txt and Address.txt, that will hold your user name and the common folder address. It will then use the START command to run Sender.bat and Receiver.bat. Sender.bat will create a text file named msgtext.txt in the address folder you specified in MessengerMain.bat. If there is already a file of this sort in existence in the address folder, it will overwrite it. Once this file is created, any message you enter will be saved in the msgtext.txt file after the name you entered (%name%: %msg%). Sender.bat the CLS (clears) the screen and asks you for another message continuously. Receiver.bat is very similar. Receiver.bat, first off, reads the Address.txt file and the Name.txt file to find your information given in MessengerMain.bat just like Sender.bat does. It will count the number of lines in the msgtext.txt file and will clear the whole screen and print out the whole contents of the file if the number of lines in msgtext.txt increases. So basically you are writing to a shared file and reading from a shared file.

Example:

I have a folder called MSGFolder located in the folder as I have my MessengerMain.bat, Receiver.bat, and Sender.bat files. I then run MessengerMain.bat by double clicking on the icon. I enter Alex for my Name and MSGFolder as the Address. I then double click MessengerMain.bat again and enter the name Bob for Name and MSGFolder for Address. Once you do this you can type in either of the Sender.bat interfaces and it will show up as if you are talking.

Batch, 117 lines
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
@ECHO off
REM MessengerMain.bat
TITLE Messanger Setup
SET /p name= Name: 

:addressChoice
ECHO.
ECHO  Enter one of the numbers below
ECHO.
ECHO  1. Use current address
ECHO  2. Enter a new address
ECHO.
SET /p newAddress= Choice? 
IF %newAddress%==1 (
SET address=C:\Users\Dad\Documents\School\BatchMSG\MSGFolder
GOTO mainPart
)
IF %newAddress%==2 GOTO addressLoop
IF %newAddress% GTR 2 (
CLS
ECHO ERROR: Enter either 1 or 2
GOTO addressChoice
)
IF %newAddress% LSS 1 (
CLS
ECHO Enter either 1 or 2
GOTO addressChoice
)

:addressLoop
SET /p address= Address: 
IF NOT EXIST %address% (
ECHO  Please enter a valid address
GOTO addressLoop
)

:mainPart
CLS
ECHO  This is a list of all current conversations in %address%:
ECHO.
DIR %address% /B | FIND ".txt"
ECHO.
ECHO  You may choose an existing filename from the list above
ECHO  or enter a new filename
ECHO.
SET /p convoDest= Enter Filename: 

ECHO %address%\%convoDest% > Address.txt
ECHO %name% > Name.txt
IF NOT EXIST %address%\%convoDest% (
ECHO. 2>%address%\%convoDest%
)

START Receiver.bat
START Sender.bat
------------------------------
@ECHO off
REM Receiver.bat
FOR /f %%a IN (Address.txt) DO (
SET address=%%a
)
FOR /f "usebackq delims=" %%a IN (Name.txt) DO (
SET name=%%a
)
TITLE Receiver: %name% - %address%
SET /a counterOld=0

:mainReader
SET /a counter=0
IF NOT EXIST %address% (
ECHO Somebody has deleted the conversation
PAUSE
EXIT
)
FOR /f %%a IN (%address%) DO (
SET /a counter+=1
)
IF NOT %counter%==%counterOld% ( 
CLS
TYPE %address%
COLOR FC
PING 1.1.1.1 -n 1 -w 800 >NUL
COLOR 07
SET /a counterOld=%counter%
)
GOTO mainReader
------------------------------
@ECHO off
REM Sender.bat
FOR /f %%a IN (Address.txt) DO (
SET address=%%a
)
FOR /f "usebackq delims=" %%a IN (Name.txt) DO (
SET name=%%a
)
DEL Address.txt
DEL Name.txt
TITlE Sender: %name% - %address%
ECHO  Enter /cls to clear the conversation
ECHO  Enter /del to delete the conversation
ECHO.

:mainPart
SET /p msg= Message: 
@ECHO %name%: %msg%>>%address%
IF "%msg%"=="/cls" (
ECHO. 2>%address%
)
IF "%msg%"=="/del" (
DEL %address%
CLS
ECHO You have ended the conversation
PAUSE
EXIT
)
CLS
GOTO mainPart

If you have any concerns of how this program works, please do not hesitate to email me at wallarelvo@hotmail.com. If there are any efficiency problems with the code, please do not leave bad comments, just polite informative comments will do just fine and I will implement your solution.

Thanks