473,395 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Preventing External File Access

I need to prevent files from being manipulated (e.g., renamed or moved) by external applications (e.g., Windows Explorer) while my app is working with the files. The length of time that my app works with the files is determined by the user (i.e., the user manually opens and closes the files). A bonus would be to prevent external applications from opening the files, but that is not required. Would using a FileStream do what I need to do, assuming that I wouldn't call the FileStream.Close method until the user chooses to close the file? Is there a better technique?

Note that the files are typically between 2 - 10MB and they can be written and/or renamed multiple times while the user is working with them. Also, I use binary serialization to save the files.

Thanks,
Lance
Nov 20 '05 #1
2 999
Cor
Hi Lance,

Did you try to do that, (moving your file while it was busy (not closed) in
your program).

Normaly that should not go at all, and is it the OS that prevent this.

So I am curious how you do that, sometimes it is asked in this newsgroup how
to delete a wrong locked file?

Cor
I need to prevent files from being manipulated (e.g., renamed or moved) by external applications (e.g., Windows Explorer) while my app is working with
the files. The length of time that my app works with the files is
determined by the user (i.e., the user manually opens and closes the files).
A bonus would be to prevent external applications from opening the files,
but that is not required. Would using a FileStream do what I need to do,
assuming that I wouldn't call the FileStream.Close method until the user
chooses to close the file? Is there a better technique?
Note that the files are typically between 2 - 10MB and they can be written

and/or renamed multiple times while the user is working with them. Also, I
use binary serialization to save the files.
Nov 20 '05 #2
Hi Lance,

Thanks for posting in the community.

From your description, I understand that you want to prevent a file being
shared by another process, also you wants to change the filename when you
have opened the filehandle.
Have I fully understood you? If there is anything I misunderstood, please
feel free to let me know.

I think by default the file will be open by setting the FileShare flag to
None, in this way, other process can not open the file.

Dim fs As New FileStream("c:\test.txt", FileMode.Open,
FileAccess.ReadWrite, FileShare.None)

Also when a file is opened it can not be moved or renamed. I am curious
why you need to rename a filename when it is opened. Maybe there will be a
better solution.

Please apply my suggestion above and let me know if it helps resolve your
problem.
Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: J C-W | last post by:
I have a directory with files (of various formats) contained within a website which uses PHP to control user access via session variables. I would like to protect the directory from direct external...
8
by: Scott Allen | last post by:
Hello, I'm new to C++ development and I'm trying out figure out the cause of an 'unresolved external symbol' error that I'm receiving when compiling. Here is some history on what I'm doing: I...
1
by: Aged | last post by:
Hi I have asked several groups now for advise but I feel I must be confusing either them or myself, but anyway here goes! Below is code taken from the "OnClick" function of a command button...
1
by: Eike | last post by:
Hi, I am unable to delete a subfolder that I have created programatically. I am using a modification of the apiSHFileOperation by Dev Ashish (http://www.mvps.org/access/api/api0026.htm) to copy...
10
by: et | last post by:
I have an asp.net program that uses a connection string, using integrated security to connect to a sql database. It runs fine on one server, but the other server gives me the error that "Login...
5
by: snicks | last post by:
I'm trying to exec a program external to my ASP.NET app using the following code. The external app is a VB.NET application. Dim sPPTOut As String sPPTOut = MDEPDirStr + sID + ".ppt" Dim p As...
1
by: lorirobn | last post by:
Hi, I have been manually importing a text file on a weekly basis to an Access table. The data on one field is about to change (happens to be the first field). It was numeric, and is defined as...
10
by: Stefan Weber | last post by:
Hi, I'm trying to access the JavaScript code contained in a <scripttag via its "text" attribute. This works well, if the code is embedded in the HTML page. However, when the code is in an...
0
debasisdas
by: debasisdas | last post by:
This thread contains some useful tips for using External tables. USING EXTERNAL TABLE ======================= 1.THE TABLE POINTS TO EXTERNAL FILE. IF DATA IS ALTERED IN THE EXTERNAL FILE,DATA...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.