Re: Detect file opened by Notepad
Don wrote:
As mentioned numerous times through this thread, notepad doesn't keep
the file open.
You may be able to do it with a tiny stub exe that opens the file, then
shells out to notepad and waits for the process to exit.
That will break if they then use that notepad process to open other files.
--
Dean Earley (dean.earley@ic ode.co.uk)
i-Catcher Development Team
iCode Systems
Don wrote:
I wrote an app that alerts a user who attempts to open a file that the
file is currently in use. It works fine except when the file is
opened by Notepad. If a text file is opened, most computers are
configured to use Notepad to open the file by default and if they are
configured to use Notepad by default I want it to remain that way
rather than retrieve the text into my app or force the user to use
another app to read the file. I'm using the following code I found
online and lErrNum returns a value of zero if Notepad has the file
open but returns 70 when most other files are open using another
application.
>
Don
>
Open sPathFile For Input Lock Read As #iFileNum
Close iFileNum
lErrNum = Err.Number
On Error GoTo 0
>
Select Case lErrNum
Case 0 'No error occurred. File is NOT already open by another
user.
FileIsOpen = False
Case 70 'Error number for "Permission Denied." File is already
opened by another user.
FileIsOpen = True
Case 53 'File not found
FileIsOpen = False
Case Else 'Another error occurred.
FileIsOpen = True
MsgBox Error(lErrNum)
End Select
file is currently in use. It works fine except when the file is
opened by Notepad. If a text file is opened, most computers are
configured to use Notepad to open the file by default and if they are
configured to use Notepad by default I want it to remain that way
rather than retrieve the text into my app or force the user to use
another app to read the file. I'm using the following code I found
online and lErrNum returns a value of zero if Notepad has the file
open but returns 70 when most other files are open using another
application.
>
Don
>
Open sPathFile For Input Lock Read As #iFileNum
Close iFileNum
lErrNum = Err.Number
On Error GoTo 0
>
Select Case lErrNum
Case 0 'No error occurred. File is NOT already open by another
user.
FileIsOpen = False
Case 70 'Error number for "Permission Denied." File is already
opened by another user.
FileIsOpen = True
Case 53 'File not found
FileIsOpen = False
Case Else 'Another error occurred.
FileIsOpen = True
MsgBox Error(lErrNum)
End Select
the file open.
You may be able to do it with a tiny stub exe that opens the file, then
shells out to notepad and waits for the process to exit.
That will break if they then use that notepad process to open other files.
--
Dean Earley (dean.earley@ic ode.co.uk)
i-Catcher Development Team
iCode Systems
Comment