Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Shell 

Local Network/Homegroup Batch Chatroom

Hi there,

After that post by IronByte asking about Chatrooms in Batch, and looking at a couple of the links posted in there I've decided to take one of them and modify it. I've left the original credit in there.

It consists of two batch files currently, one is simple; "ChatDisplay.bat" does what it says on the tin, it displays the chat log, updating every second.

Code
@echo off
set logloc=
title Chatroom Display
:display
cls
type %logloc%log.dat
timeout 1 >nul
goto display

The main batch, (I named it ChatroomMain.bat, for whatever reason my brain came up with at the time, it doesn't particularly matter right now.) is the one that allows for a user to actually add messages to the chat log, clear the log, and exit.

Code
@echo off
rem: Matthew Merchant ScriptingMadness.blogspot.com Improved by gogglebot @ HackForums.net
rem ###### TITLE SCREEN ######
title Batch Chatroom Input
color f0
set logloc=
echo.
echo Welcome to The Batch Chatroom.
echo.
echo Commands:
echo Type CLS to clear the chat log, please avoid excessive use!
echo Type EXIT to quit the chat room, rather than closing the window.
echo.
echo Don't be mean to people!
echo.
set /p username=What is your name?
echo %username% has joined from %computername%. >> "%logloc%log.dat"
title Batch Chatroom Input: %username%
set lastmessage=""
cls
goto CHATLOOP
REM ######

REM ###### CHAT LOOP ######

:CHATLOOP
set /p message=Say:

rem set message checker value
set thismessage="%message%"

rem check for exit
if %thismessage% == "EXIT" echo %username% has left the chat room. >> "%logloc%log.dat"&& exit
if %thismessage% == "exit" echo %username% has left the chat room. >> "%logloc%log.dat"&& exit

rem ------

rem check for clear
if %thismessage% == "CLS" goto clear
if %thismessage% == "cls" goto clear
goto noclear

:clear
for /f "tokens=1,2,3,4 delims=/ " %%a in ('Date /t') do (
set dayw=%%a
set day=%%b
set month=%%c
set year=%%d
)
for /f "tokens=1,2 delims=: " %%a in ('Time /t') do (
set hour=%%a
set mins=%%b
)
copy "%logloc%\log.dat" "%logloc%log-%day%%month%%year%-%hours%%mins%.old"
echo %username% from %computername% has cleared the chat log. > "%logloc%log.dat"
set message=Empty
set lastmessage="Empty"
goto CHATLOOP
rem ------

:noclear
rem check for same message as last time
if %thismessage% == %lastmessage% echo You said that last time!&& goto CHATLOOP

rem if all checks out, go ahead and post this message
echo %username%: %message% >> "%logloc%log.dat"

rem save value for next test
set lastmessage="%message%"

goto CHATLOOP

REM ####END OF CHAT LOOP ####

On start up you can set your username, this will mark all your chats. It then outputs %username% has joined from %computername%.
This helps to avoid confusion if someone starts up two of them with different names on the same PC, everyone can see that it's the same one.

When you clear the log (by typing CLS or cls) it copies log.dat to "log-datehere-timehere.old" (in the format DDMMYYYY-HrsMins) and empties log.dat, leaving the message "%username% has cleared the chat log."
Note: I need to add seconds to this to avoid overwrites in the case of a minute not passing between two clears. Any pointers?

Typing either EXIT or exit will send the message "%username% has left the chat."

The batch will stop you sending the same thing twice, in an anti-spam attempt.

To use this with users on a network, you'd need to have a folder on one of the machines or on a server that is shared with all the users, with read\write permissions. You'll then need to set the logloc variable at the top to this folder, above I have left it blank. So it'd likely be \\HOST-NAME\chatroom\

IMPORTANT NOTE REGARDING THE LOCATION:
THE TRAILING '\' IS IMPORTANT! DO NOT INCLUDE ""s AROUND IT, THE CODE DOES THIS ON ITS OWN, INCLUDING THEM YOURSELF WILL BREAK IT.

Note: Avoid using the | pipe character as this has a tenancy to break stuff also.
Note2: Remember if there's no log.dat ChatDisplay will not work until there is one, make sure logloc is correctly set in both files and that log.dat exists.

Screenshots, using this and my old laptop connected on a homegroup network.

Spoiler (Click to View)

I hope someone somewhere finds this useful, Enjoy HF! Please report any issues (and a fix, if you can!)
Keep me fed and alive at Uni: Bitcoin Bitcoin: 16cwoYXfhaK6V5c8kJKn9SBMtDUARUs7BS
I'll draw terrible art in paint.NET for you, on request, in return <3
Wow Really Nice work , Thanks for sharing......This Chat rooms are useful
(Aug 29, 2014 08:46 AM)Xervo Wrote:  Wow Really Nice work , Thanks for sharing......This Chat rooms are useful

You're welcome :) Good to get some feed back!
There's better options out there, this one's just very small and simple and needs no installation on other machines, which is nice, just stick em in a shared network folder and you're done!
Keep me fed and alive at Uni: Bitcoin Bitcoin: 16cwoYXfhaK6V5c8kJKn9SBMtDUARUs7BS
I'll draw terrible art in paint.NET for you, on request, in return <3
Im trying this out this Evening, if it actually works would be great like :D
(Aug 29, 2014 09:39 AM)jeroendj2 Wrote:  Im trying this out this Evening, if it actually works would be great like :D

Cool, tell me if you have any issues!
Keep me fed and alive at Uni: Bitcoin Bitcoin: 16cwoYXfhaK6V5c8kJKn9SBMtDUARUs7BS
I'll draw terrible art in paint.NET for you, on request, in return <3
Thanks for the share, pretty nifty.
[Image: New-Signature-v2.png]
good work with this it really got my creative gears working for the last couple days. I have included it in my HTA that I use at work I'll be releasing the HTA here in a little bit after I finish sanitizing it with you credited for this. I made some changes to it so it now posts to a dynamic HTML document rather than another batch.
There's no place like ~/
Nice one bro! :)
Really originally and not seen before!
(Aug 29, 2014 11:03 AM)b00st3d Wrote:  good work with this it really got my creative gears working for the last couple days. I have included it in my HTA that I use at work I'll be releasing the HTA here in a little bit after I finish sanitizing it with you credited for this. I made some changes to it so it now posts to a dynamic HTML document rather than another batch.

Awesome man glad I could help :D
(Also awesome something I've made is getting used in "the wild" 😁 ✌ ) I'd like to see the changes! Viewing in a browser would be awesome!

EDIT: Just read the name of it in your HTA thing, batCHAT. Awesome. :D
Keep me fed and alive at Uni: Bitcoin Bitcoin: 16cwoYXfhaK6V5c8kJKn9SBMtDUARUs7BS
I'll draw terrible art in paint.NET for you, on request, in return <3
Hey bro, i tested it out on my pc and it works, kinda funny :)
But i got one thing, how can I like chat to someone on the same network? As the log.dat is saved on 1 pc
(Aug 30, 2014 12:48 AM)jeroendj2 Wrote:  Hey bro, i tested it out on my pc and it works, kinda funny :)
But i got one thing, how can I like chat to someone on the same network? As the log.dat is saved on 1 pc

I guess both of the computers you want to talk between are connected to the same router? Is this at home? If its at home and you have a newer Windows version then it should have homegroups on it, google a tutorial if you're unsure on how to set up a homegroup and share folders between two computers on it. Once you've got both computers connected to the homegroup, you'll need to make the folder that has the bat files and log in it shared with your homegroup and make sure that homegroup has read AND write permissions to that folder, so they can add messages to the log and read the files and the log back. Remember to set the logloc variable to point to \\HOST-MACHINE\foldershere\chatroom\
(substituting the computer name and the directories)

This way when other users run it it points to that folder on the host computer rather than trying to find the non-existant folder C:\folders\chatroom\ on themselves, it does come up with an error at first when you run it from another machine saying it doesn't support UDC or something like that, this I do here is a work around, so you can ignore that error, I was trying to find a way to hide it.

To make it easier I myself put it on this laptop straight onto C:\chatroom\
so all I had to type in logloc was \\LAPTOP-NAME\Chatroom\ and that was it, share the Chatroom folder with homegroup and join it from my other laptop and I could talk between them :)

IF on the otherhand you're doing this on a network that isn't at home, Are you the/one of the admin(s)? If no, don't do it! ask about it first :p

If you are it's a similar process, you just need a folder that's on the network that's shared with all the users on that network, rather than sharing with homegroup, if it's got public computers then you might want to find a way to only share write ability to log.dat and file creation in the folder, etc. As someone could tamper with the batch files. Of course if it's all trusted people then you don't need to bother.

I guess you have some understanding of batch, so if you wanted it to show the username of the person logged on the computer rather than letting them set their own username, just remove the bit where they set it and it'll default %username% to whoever's logged on's pc username. In a workplace I imagine you'd do this.
Keep me fed and alive at Uni: Bitcoin Bitcoin: 16cwoYXfhaK6V5c8kJKn9SBMtDUARUs7BS
I'll draw terrible art in paint.NET for you, on request, in return <3
oh yea thanks for the information! loveu
Hello, thought I'd make something for this, it's a sort of announcement maker, it's (yet another) batch file that loops through various announcements that an Admin could set and posts them to the chat, occasionally clearing the chatlog to avoid flooding it (when it gets big ChatDisplay starts to have a significant lag-flash before it shows everything again. )
An admin could just have this running in the background, it requires no attention aside from setting the announcements.
Code
@echo off
title batCHAT Announcer
set logloc=\\EXAMPLE-PCNAME\chatroom\
:top
timeout 5 >nul
echo Announcements starting...
echo [Announcer]: Announcement1 >>%logloc%log.dat
echo 1
timeout 120 >nul
echo [Announcer]: Announcement2 >>%logloc%log.dat
echo 2
timeout 120 >nul
echo [Announcer]: It's my birthday in 26 months, ya'll better remember. >>%logloc%log.dat
echo 3
timout 120 >nul
echo [Announcer]: Announcement4 >>%logloc%log.dat
echo 4
timout 120 >nul
echo [Announcer]: Announcement5 >>%logloc%log.dat
echo 5
timout 120 >nul
echo [Announcer]: Announcement6 >>%logloc%log.dat
echo 6
REM Done, clear log.dat
echo All announcements done, clearing log...
echo [Announcer]: Automatic log clearing in a few seconds... >>"%logloc%log.dat"
timeout 5 >nul
for /f "tokens=1,2,3,4 delims=/ " %%a in ('Date /t') do (
set dayw=%%a
set day=%%b
set month=%%c
set year=%%d
)
for /f "tokens=1,2 delims=: " %%a in ('Time /t') do (
set hour=%%a
set mins=%%b
)
copy "%logloc%log.dat" "%logloc%log-%day%%month%%year%-%hours%%mins%.old"
echo The log has been automatically cleared >%logloc%log.dat
goto :top

Also:
I found an issue.
Near the bottom of chatroommain.bat I accidentally put a '/' between %logloc% and log.dat. I believe this will cause issues. Please locate and remove this slash from your local versions, if it's there.

Also there's an issue with writing the hour into the .old logs, I'm unsure why this is occurring, so am unable to fix it at this time, if you have a fix, please tell me!
Keep me fed and alive at Uni: Bitcoin Bitcoin: 16cwoYXfhaK6V5c8kJKn9SBMtDUARUs7BS
I'll draw terrible art in paint.NET for you, on request, in return <3
Dayum man... this is where it's at :) Great job on this... I'm gonna see what I can add to it, etc... Thanks for this :)
(Aug 31, 2014 01:17 AM)nuk Wrote:  Dayum man... this is where it's at :) Great job on this... I'm gonna see what I can add to it, etc... Thanks for this :)

Glad you like it :) Share what you add I'd love to expand this.
Keep me fed and alive at Uni: Bitcoin Bitcoin: 16cwoYXfhaK6V5c8kJKn9SBMtDUARUs7BS
I'll draw terrible art in paint.NET for you, on request, in return <3


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Shell] by Robert RougeSep 24, 2026 10:02 AM 4 222 Sep 24, 2026 10:02 AM
Last Post: Anonynuk
[Release] by Young GeorgeFeb 5, 2024 03:59 PM 9 319 Feb 5, 2024 03:59 PM
Last Post: Suspect.
[Shell] by fisica638Oct 30, 2019 11:05 AM 1 536 Oct 30, 2019 11:05 AM
Last Post: Hackoo