Persistent DOSKEY and logging everything

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
aisha
Posts: 26
Joined: 28 Sep 2016 06:40

Persistent DOSKEY and logging everything

#1 Post by aisha » 14 Jun 2017 07:11

Hello all,
This morning I was asked a rather unusual question, "can you in DOS make a command into an alias that runs the actual command typed in, but also echoes exactly what is typed into a log file along with a date/time-stamp? And it needs to be persistent on start up."

My first thought was definitely doskey, so:
DOSKEY ls=dir
will make the "dir" command run when "ls" is typed

The next part, persistence, seems solved with:
https://gist.github.com/vladikoff/38307908088d58af206b

However, I am really not coming up with a good way to make a log file of whatever gets typed.
I figure we can doskey anything, so if the syntax gets figured out then we could doskey the original command, plus the logging.
So if someone types
"net use c:\users\renfro\"
then it would end up echoing into a log file:
06/14/2017 09:08:00
net use c:\users\renfro\

I hope this question makes sense - it would really help solve a significant issue on our side
I recognize we would need to create a doskey for maybe a dozen dos commands.

-Aisha

misol101
Posts: 475
Joined: 02 May 2016 18:20

Re: Persistent DOSKEY and logging everything

#2 Post by misol101 » 18 Jun 2017 04:33

Maybe I don't understand the question completely (it's a bit vague), but perhaps something home-cooked like:

Code: Select all

@echo off
setlocal
set OUTFILE=log.txt
del /Q %OUTFILE% >nul 2>nul

:LOOP
   set INPUT=
   set /p "INPUT=> "
   if "%INPUT%"=="" goto LOOP
   if "%INPUT: =%"=="" goto LOOP
   echo %DATE% %TIME% >>%OUTFILE%
   echo %INPUT% >>%OUTFILE%
   if "%INPUT%"=="quit" goto :eof
   %INPUT%
   echo(
goto LOOP
endlocal


And then just use Doskey to set the macros before running this script

Post Reply