How do i find out if a file is locked?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sevak316
    New Member
    • Sep 2008
    • 73

    #16
    George666,

    If I were to learn the MSDN library (like you described), why would I be in this forum? It is not as easy as you think. I am here to ask advice from the experts so I can learn and save some time banging my heard against the table.

    If you know an API call that can use to tell if a file is being used by another process, please by all means let me know. I have not been successful with that. I have not only looked at MSDN, but also Google has been my friend as well.

    The closest Ive gotten to accomplish this task is using the CreateFile function, which so far has not been workin.

    Comment

    • donbock
      Recognized Expert Top Contributor
      • Mar 2008
      • 2427

      #17
      Let's start over. What are you trying to do with these files and why do you think it is helpful to explicitly check if they are locked?

      Comment

      • sevak316
        New Member
        • Sep 2008
        • 73

        #18
        Ok Don,

        I am using Windows XP.

        I have this modeling program. I create a project in this program. The project files are located on a network drive. Multiple users can open the project and view what is inside the project AT THE SAME TIME.

        There are all these files which are associated with this project. There is one particular file that gets locked if the project is open by one or more users. I know this for sure because when I try to Zip the project files (while the project is open), WinZip warns me about this file being used by another process. If the project is closed and no user is accessing it, WinZip does not give me this warning message. Also, the program itself tells me that this file is LOCKED and it cannot be saved when the project is open by multiple users.

        I am trying to write a program that will constantly monitor this file and tell me if it’s locked or not. This way I know when the project files are free or if they are in use.

        That is all.

        If you have any ideas, please let me know.

        Thanks.

        Comment

        • Banfa
          Recognized Expert Expert
          • Feb 2006
          • 9067

          #19
          How about rather than having everyone open the files from the network you set-up a source control repository (like subversion) on the network to contain these (and other) project files and then let everyone check out a local copy of the files to work on / view.

          Then the problem of someone having a file lock just doesn't occur.

          Comment

          • sevak316
            New Member
            • Sep 2008
            • 73

            #20
            Banfa,

            thats in the process. this is a temp fix.

            Comment

            • donbock
              Recognized Expert Top Contributor
              • Mar 2008
              • 2427

              #21
              Originally posted by sevak316
              I am trying to write a program that will constantly monitor this file and tell me if it’s locked or not. This way I know when the project files are free or if they are in use.
              What is your motivation for monitoring this information? What harm does it do to let your users run wild, getting error messages when they interfere with each other?

              Does this modeling program itself provide a feature to report which users have a given project open?

              Comment

              • sevak316
                New Member
                • Sep 2008
                • 73

                #22
                maybe i should let them go wild. I'll warm up some popcorn, lay back and watch the show.

                the program doesnt provide info. I already looked at their log files.

                I am just shocked that windows api doesnt have a simple function which return yes if the file is in use and returns falls otherwise. I have tried different api calls and non of them give me a consistant answer.

                Comment

                • donbock
                  Recognized Expert Top Contributor
                  • Mar 2008
                  • 2427

                  #23
                  When you ask the modeling program to open a file, does it give you the choice of opening it as either read-only, shareable-edit, or exclusive-edit?

                  Comment

                  • sevak316
                    New Member
                    • Sep 2008
                    • 73

                    #24
                    no, it doesnt.

                    can you please tell me why windows doesnt have a simple function which will tell you if the file is being used or not. Do you think that is an easy task to accomplish?

                    Comment

                    • donbock
                      Recognized Expert Top Contributor
                      • Mar 2008
                      • 2427

                      #25
                      Originally posted by sevak316
                      can you please tell me why windows doesnt have a simple function which will tell you if the file is being used or not.
                      There's no answer to this existential question -- we can't read Bill Gates' mind. Don't get me started on the virtues, or lack thereof, of the Windows operating system.

                      I may be a little dense, but I still don't understand why you don't let your users run wild. The only inconvenience is that a user seeking to change the project will get an error message, will then have to send an email to the team asking them to exit the program, wait til he's alone and then finish changing the project. Is this really so terrible ... especially if you're working on a long-term solution via a source code repository?

                      Comment

                      • sevak316
                        New Member
                        • Sep 2008
                        • 73

                        #26
                        The main reason is that they can replace each other. If one user is working on a different version of the project than another user, they can end up replacing each others work when they go ahead and save the project. Thats why I am trying to make this an easy task for everyone rather than sending each other e-mails to know if they can use the project, they will just have to run this program that constantly checks the project files for them.

                        I thought it would be a nice idea, but too bad Microsoft is not smart to come up with this function.

                        Comment

                        • donbock
                          Recognized Expert Top Contributor
                          • Mar 2008
                          • 2427

                          #27
                          Originally posted by sevak316
                          The main reason is that they can replace each other. If one user is working on a different version of the project than another user, they can end up replacing each others work when they go ahead and save the project. Thats why I am trying to make this an easy task for everyone rather than sending each other e-mails to know if they can use the project, they will just have to run this program that constantly checks the project files for them.
                          I thought you said that any number of people can open the project, but changes cannot be saved if more than one person has the project open.

                          If that's the case, then suppose ten people open the project, with two of them being editors intending to change it. Everybody is able to open the project without any errors or warnings. The first editor to finish his changes tries to save and gets an error. He then sends out an email to the team asking everybody to close the project. The second editor is forced to abandon his changes when he closes the project. The first editor successfully saves his changes and notifies the team that the project is open for business again.

                          It is no fun to have to abandon your changes, but at least one set of changes won't silently replace another.

                          Comment

                          • weaknessforcats
                            Recognized Expert Expert
                            • Mar 2007
                            • 9214

                            #28
                            I think this is all handled by Source Depot when ties to Visual Studio. It's the source control system that allows multiple checkouts amd merge of changes on the check-in.

                            I think Visual SourceSafe does this also.

                            Comment

                            • sevak316
                              New Member
                              • Sep 2008
                              • 73

                              #29
                              Donbock: there is no way for a user to abandon their changes after 4 hours of hard labor.
                              weaknessforcats : we are definitley going to use a source control system very soon. I just wanted a quick fix. That is all.

                              Thank you guys anyways, but the problem seems to be with Microsoft and their API.

                              -Sevak

                              Comment

                              • donbock
                                Recognized Expert Top Contributor
                                • Mar 2008
                                • 2427

                                #30
                                You can allow any number of readers but you need to limit the number of editors to one. If you can do this then the worst impact is that the editor will ask all the readers to exit the application for a few minutes when he saves his changes.

                                You can implement quick-and-dirty low-tech edit locking by creating a token. Only the person holding the token is allowed to edit the file. The token should be something big and noticeable -- perhaps a stuffed animal. Apply appropriate punishments to anybody caught editing without the token or not returning the token when finished. You can retire the token when the source code control system is working.

                                Although this token approach relies on your developers following the rules; that's not much different from your notion of supplying a utility that you expect your developers to run before they open the project.

                                Comment

                                Working...