Detect file opened by Notepad

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dean Earley

    #31
    Re: Detect file opened by Notepad

    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
    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

    Comment

    • Don

      #32
      Re: Detect file opened by Notepad

      On Mon, 15 Sep 2008 06:06:51 -0700, "Bob Butler" <noway@nospam.e ver>
      wrote:
      >
      >"Don" <dsarvas@yahoo. comwrote in message
      >news:48ce5ae2. 2596437@news.we st.cox.net...
      >On Sun, 14 Sep 2008 14:14:07 -0400, "expvb" <nobody@cox.net wrote:
      ><cut>
      >So I will probably go back to exactly what you are suggesting above or
      >create a detour to another app I konw they have on their system that
      >will open a text file and keep the file open.
      >
      >How about opening the file exclusively from your app, copying the contents
      >to a temp file, shelling the default editor on that copy and waiting for it
      >to terminate, then updating the original and deleting the temp file?
      >
      Hey, I like that.

      I was already using a simlar function to work on a temp file, but I
      was using my own app and I wasn't locking the original with my own app
      while doing so. But to allow the user to use Notepad, if that's their
      default app for a text file, and monitor its use so the original file
      remains locked during the interim sounds interesting.

      Although this has great possibilites, I'm not sure how confident I
      will be using it due to concerns I mentioned previously regarding the
      consequences that might result if the program shuts down unexpectedly
      and we're left with the original file locked . . .OR would the file
      detect that my app has shut down and revert back to being available?

      Although I have decided to either detour the user to another app or
      use my own app to read the file and either of those solves the
      problem, I'm going to have to give your suggestion some thought. I
      have a long ride to work so I have a long way to think about this.
      Don

      Comment

      • Don

        #33
        Re: Detect file opened by Notepad

        Although it has absolutely NO relevence to this thread, in researching
        ways to get around my problem with Notepad I discovered something I
        didn't know.

        If you type "Bush hid the facts" (no quotes and no period) in Notepad
        and save the file, when you open the file you won't see the phrase. I
        won't spoil it by giving the explanation here, but you can Google your
        way to the explanation. Try Googling "Things you can't type in
        Notepad" and I think you'll find it.

        Don


        On Sat, 13 Sep 2008 17:28:13 GMT, dsarvas@yahoo.c om (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
        >
        >

        Comment

        • dpb

          #34
          Re: Detect file opened by Notepad

          PeterD wrote:
          ....
          Rename *what* file? No where did I suggest renaming files. What file
          are you opening? A .TXT file?
          ....

          I think multiple suggestions are getting mixed up...iirc somebody did
          suggest renaming in some fashion would allow an individual user to make
          changes. Of course, that raises the issue of then having to try to
          somehow merge the changes or simply ignoring some over the acceptance of
          others.
          >receive so many files from so many sources it would have to be done
          >this way rather than renaming every file as we receive them manually.
          >
          OK, so what is the purpose of this exercise?
          Absolutely no clues to that have been offered, but it's clear they need
          to check each received file into a version control system and only
          retrieve/use files from that repository via a single-user-at-a-time
          option for check out for modifications although allowing multiple
          viewing might be desirable.

          With that, I'm now going to mark the thread "ignore"...

          ....

          --

          Comment

          • Bob Butler

            #35
            Re: Detect file opened by Notepad

            "Don" <dsarvas@yahoo. comwrote in message
            news:48ce6af9.6 715546@news.wes t.cox.net...
            Although this has great possibilites, I'm not sure how confident I
            will be using it due to concerns I mentioned previously regarding the
            consequences that might result if the program shuts down unexpectedly
            and we're left with the original file locked . . .OR would the file
            detect that my app has shut down and revert back to being available?
            If there is a crash or your app aborts for any reason then recovery would
            depend on whether you've saved the state of "user x is editing text y in
            location z" somewhere. If you didn't then any changes are lost and if you
            did you can decide to restart the editing session (maybe asking the user in
            case it's an endless loop).

            If the user's text editor crashes then you should see it terminate and can
            take precautions -- maybe check the return value of the editor app and if
            not 0 then ask the user to confirm that it is OK to update.... maybe compare
            the before & after versions and if the sizes aren't close ask the user to
            confirm... nothing is ever going to be foolproof so it's up to you to
            decide how many hoops you want to jump through and how many you want to
            force your users through.

            As soon as you do this you're going to find users editing the text on the
            originals while your app is not running. Unless you're encrypting the text
            and putting it in a difficult-to-find location the users are going to find a
            way around any restrictions you set. Even if you do those things somebody
            probably still will. *&%^&^%^& users!



            Comment

            • Steve Gerrard

              #36
              Re: Detect file opened by Notepad

              Don wrote:
              >
              That is how my app originally functioned and the purpose of this
              thread. Since Notepad is a default on most systems I wanted to take
              advantage of allowing the user to remain using Notepad, but prevent
              other users from accessing the file.
              Don
              >
              But two users can both use Notepad on the same file. Your app has nothing to do
              with it. That is the problem.


              Comment

              • Mike Williams

                #37
                Re: Detect file opened by Notepad

                "Don" <dsarvas@yahoo. comwrote in message
                news:48ce6da7.7 401281@news.wes t.cox.net...
                If you type "Bush hid the facts" (no quotes and no period) in
                Notepad and save the file, when you open the file you won't
                see the phrase. I won't spoil it by giving the explanation here,
                but you can Google your way to the explanation. Try Googling
                "Things you can't type in Notepad" and I think you'll find it.
                Actually I can't reproduce that problem in the version of NotedPad that
                comes with Vista, either on that phrase or on any of the other phrases I've
                just discovered on the Internet. I must make a mental note to try it on
                other systems though when I get the time. Never come across it before.
                Sounds vaguely interesting :-)

                Mike




                Comment

                Working...