Link to home
Start Free TrialLog in
Avatar of Michael Spellman
Michael SpellmanFlag for United States of America

asked on

Track use of a script by logging username, date & time to an excel file.

We have a batch file that users can run to copy their user profile data to their network user folder.  When someone runs the file, I'd like to create a record that contains the username, date/time in an excel file.

Echo Off
cls
Echo _________________________________________________________________________
Echo This will copy your favorites, desktop icons, documents and your pictures 
Echo to your H-drive.
Echo Your stocks interview files will not be copied.
Echo _________________________________________________________________________
pause

cls
Echo please wait while your files will be copied...

h:
cd\
md _swing
cd _swing
md desktop
md downloads
md favorites
md documents
md pictures


robocopy %userprofile%\desktop h:\_swing\desktop /s /e /r:1 /w:1 /log+:h:\_swing\swing.log
robocopy %userprofile%\downloads h:\_swing\downloads /s /e /r:1 /w:1 /log+:h:\_swing\swing.log
robocopy %userprofile%\favorites   h:\_swing\favorites /s /e /r:1 /w:1 /log+:h:\_swing\swing.log
robocopy %userprofile%\documents h:\_swing\documents /s /e /r:1 /w:1 /log+:h:\_swing\swing.log
robocopy %userprofile%\pictures h:\_swing\pictures /s /e /r:1 /w:1 /log+:h:\_swing\swing.log

c:
cd\
cd %userprofile%
cd "AppData\Local\Google\Chrome\User Data\Default"
copy bookmarks h:\_swing >> h:\_swing\swing.log
echo %computername% >> h:\_swing\swing.log

cls
Echo __________________________________________________________
Echo Your favorites, desktop icons, documents and your pictures
Echo has been copied.
Echo ___________________________________________________________

pause
exit

Open in new window

swing_bat.txt
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If for some reason, you must update an Excel file, rather than use Bill's elegant .csv solution above, then In theory you can open an Excel file direct from the batch file using, eg:
call "c:\neil work\software\excel\expertsexchangequestions\autolog.xlsm" 

Open in new window


Rather than try to pass parameters to the Excel file, which is a nightmare, you could then log the username using the "Workbook_Open" event and "application.username". Then have the workbook close itself automatically unless the username matches that of an admin (you need a way to stop it automatically closing itself, if you ever want to open it again :) )

But the same issues apply with regard to simultaneous updates as with the preceding comments.
Avatar of Michael Spellman

ASKER

That works.  It at least lets me track who has run it.