VB Script & BAT : identify who has modify a file

Hello experts,

I was wondering how can I identify who has done the last modification in a file.
The idea is to have a script which checks all the files in a RefFolder and output a log-files composed by the following information:
File1.xls last modification done by """" at ""
File2xls last modification done by "" at """"


Thank you in advance for your help.
LVL 1
LD16Asked:
Who is Participating?
 
Bill PrewCommented:
Give this a try:

' Text file I/O constants
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8

'Create the file system object for creating folders:
Set objFSO = CreateObject("Scripting.FileSystemObject")

' Create Excel application
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = False

' Define folders and files to work with
strBaseDir = "B:\EE\EE28630453\Files"
strLogFile = objFSO.GetAbsolutePathName(".") & "\modify-log.txt"
strFileFilter = ".xls"

' Make sure input folder exist
If Not objFSO.FolderExists(strBaseDir) Then
   Wscript.Echo Now & " ERROR: Input folder """ & strBaseDir & """ does not exist."
   Wscript.Quit
End If

' Open log file for appending
Set objLog = objFSO.OpenTextFile(strLogFile, ForWriting, True)

' Process all files in folder
For Each objFile In objFSO.GetFolder(strBaseDir).Files

   ' Make sure it matches the files we want to copy
   If LCase(Right(objFile.Name, Len(strFileFilter))) = LCase(strFileFilter) Then

      ' Load the file into excel
      Set objWorkbook = objExcel.Workbooks.Open(objFile.Path)

      ' Gather desired Office metadata (https://msdn.microsoft.com/en-us/library/microsoft.office.tools.excel.workbook.builtindocumentproperties.aspx)
      strLastSaveTime = objWorkbook.BuiltinDocumentProperties("Last Save Time")
      strLastAuthor = objWorkbook.BuiltinDocumentProperties("Last Author")

      ' Close this file in excel
      objWorkbook.Close False
      Set objWorkbook = Nothing

      ' Log info for this file
      objLog.WriteLine """" & objFile.Name & """ last modification done by """ & strLastAuthor & """ at """ & strLastSaveTime & """"

   End If

Next

' Wrap up
objLog.Close
objExcel.Quit

Open in new window

~bp
0
 
NVITCommented:
Make a .bat of this:
@echo off
setlocal
set fn=*.*

for /f "tokens=1-6" %%a in ('dir /q "%fn%"') do (
   if /i "%%f" neq "" (
      if /i "%%f" neq "no" echo "%%f" last modification done by "%%e" at "%%a %%b %%c"
   )
)

Open in new window

0
 
LD16Author Commented:
@NewVillageIT: if I want to specify an specific variable for the folder and a log-file.txt to write the last modification done by? How can I do it this?
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
NVITCommented:
@echo off
setlocal
set FNPatt=*.*
set FNLog=%userprofile%\documents\log-file.txt

for /f "tokens=1-6" %%a in ('dir /q "%FNPatt%"') do (
   if /i "%%f" neq "" (
      if /i "%%f" neq "no" echo "%%f" last modification done by "%%e" at "%%a %%b %%c">>"%FNLog%"
   )
)

Open in new window

0
 
Bill PrewCommented:
Windows doesn't normally store the user that last modified a file.  If you enable object access logging then you can extract that from the security event log.  But that has to be set up on each machine desired.

Are you just interested in XLS files, there may be another option if so.

~bp
0
 
LD16Author Commented:
@Bill: thank you for your feedback, I am just interesting in xls and if possible in csv, however if there a reliable way just for xls I am in.
0
 
LD16Author Commented:
Great, it works! Thank you!
0
 
Bill PrewCommented:
Welcome.

~bp
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.