Solved

Locking a file

Posted on 1998-06-23
7
153 Views
Last Modified: 2011-09-20
I am using VB4.0 32-bits, and I wish to know how can I lock certain files from other user using it if
one user is already using it.

Something like microsoft word, where if I am already using docA.doc, and user B from another computer can only view this docA.doc but cannot modify it. However, I perfer that user B cannot even view it at all, if the file is being used.

Is there a way I can code it?
0
Comment
Question by:wsm
  • 3
  • 2
  • 2
7 Comments
 
LVL 1

Expert Comment

by:raygibbins
ID: 1464023
In your code you could create a file called docA.loc when a user  opens docA.doc for the first time. This lock file could contain things like user name etc. When another user wants to open docA.Doc the program first look for docA.loc. If docA.loc exists then you could read it and display a messagebox showing who has it open.
Code would be
If Dir$("c:\temp\docA.loc")<>"" Then
     'Read the lock file and display messagebox
End If

When the docA.doc is closed then the program would delete the lock file
0
 

Accepted Solution

by:
Ajoy earned 100 total points
ID: 1464024
you can use the key word app. This supports certain  properties out of which you can use the instance property.
if app.instance then don't run the file.
if this does not work then get back to me at atarafder@hotmail.com. i would be glad to help you
0
 

Author Comment

by:wsm
ID: 1464025
Ajoy,

I am not very sure what you are saying. Can you give a little bit more
details and example which I can look at?

I think raygibbins has given another good example. However, I do not wish to
create too many "temp" files just for this purpose, if possible.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Expert Comment

by:raygibbins
ID: 1464026
My example is the similar to the way Microsoft and AutoDesk do it.
0
 

Author Comment

by:wsm
ID: 1464027
I notice that, but like I said before I do not wish to add any more "temp" files to the current directory. I have already added some other "temp" hidden files into that directory. Only when I cannot find any other solution to solve this then I will use this creating "temp" file.

I would really appreciate if you can give me any other ideas beside this one.
Thanx inadvance.
0
 

Expert Comment

by:Ajoy
ID: 1464028
wsm,
Before i can give you more details, Could you please tell me if your application is client/server based or a simple application.if your application isc/s based and the application runs on the server then what i said above can easily be implemented.
0
 

Author Comment

by:wsm
ID: 1464029
it is just a normal application that runs on win95. This should or might be a networked environment, but it is not a client/server application. If it is a networked environment, then those files are located at a shared directory
whereby users are allowed to access it. That is why I need some sort of codes
or function that will let people knows if that file is being used by another person.

 Hope u can understand what I am trying to say here.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now