Script that checks if a file is opened

November 11, 2010 at 23:36:32
Specs: Windows XP
Hi,

I would like a .bat script that checks if a FILENAME.doc(txt) is opened. I don't want to know if the process WINWORD.exe or notepad.exe is running, I want to know about a certain file.
Is it possible to also know the user that opened that file?

Thank you!


See More: Script that checks if a file is opened

Report •


#1
November 25, 2010 at 18:09:22
I'm not sure if that is possible. This is the only code I can think of which detects the file application:

tasklist /FI "IMAGENAME eq myapp.exe" 2>NUL | find /I /N "myapp.exe">NUL
if "%ERRORLEVEL%"=="0" echo Programm is running


You may need to do a work-around. If you tried this:


@echo off
tasklist /FI "IMAGENAME eq file.doc" 2>NUL | find /I /N "file.doc">NUL
if "%ERRORLEVEL%"=="0" echo Programm is running
pause>nul


it would not work because the DOC file isn't EXE.


Report •

#2
November 25, 2010 at 19:33:42
Actually, I'm not sure if windows still does this but, when a file was opened, a temp file was created, so it sould be as simple as checking if that file exists.

Can I put a question here?


Report •

Related Solutions


Ask Question