Page 1 of 1

Persistent DOSKEY and logging everything

Posted: 14 Jun 2017 07:11
by aisha
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

Re: Persistent DOSKEY and logging everything

Posted: 18 Jun 2017 04:33
by misol101
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