473,767 Members | 2,226 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

opening a allready opened file (pfirewall.log)

I am trying to open %windir%\pfirew all.log.
and I just can't get it to work (I am a absolute newbie to VB.net)

the strange thing is that notepad is perfectly able to view the file. but my
code keeps failing.

amongst other things i tried:
Dim s2 As New System.IO.FileS tream(FileName, System.IO.FileM ode.Open,
System.IO.FileA ccess.Read, System.IO.FileS hare.Read)

I keep getting this error when i try to open it:

An unhandled exception of type 'System.IO.IOEx ception' occurred in
mscorlib.dll

Additional information: The process cannot access the file
"C:\WINDOWS\pfi rewall.log" because it is being used by another process.
does anyone know how i can open this file allthough it is locked by the
firewall?

Omko Huizenga
Nov 21 '05 #1
4 3752
The key is in the FileShare parameter you used. When you pass
FileShare.Read, you are saying: "Open the file such that other
programs can only read from the file while I am using it". Since the
firewall has already opened the file to write to it, your FileShare
mode fails. Try using the FileShare.ReadW rite value instead and see
if that helps.

Nov 21 '05 #2
thanks a lot! it works.
but i don't realy get it. does this mean that when i open a file that is
allready opened, I have to match the type of lock that is on that particular
file??
Omko

"Chris Dunaway" <du******@gmail .com> schreef in bericht
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
The key is in the FileShare parameter you used. When you pass
FileShare.Read, you are saying: "Open the file such that other
programs can only read from the file while I am using it". Since the
firewall has already opened the file to write to it, your FileShare
mode fails. Try using the FileShare.ReadW rite value instead and see
if that helps.

Nov 21 '05 #3
You don't have to match it, but whatever lock you use must not be
contrary to the lock used by the other program.

For example, if the other program had opened the file using
FileShare.None, then you would not be able to open the file at all.

FileShare.None means "Open the file and don't allow any other program
to open it for any reason."

FileShare.Read means "Open the file and only allow other programs to
read from the file but not write to it"

FileShare.Write means "Open the file and only allow other programs to
write the file, but not read it."

FileShare.ReadW rite means "Open the file and all other programs to read
from and write to the file."

In general, whoever opens the file first has control over how other
programs can access the file. If the firewall had not allowed read
access, you would not have been able to open the file for reading.

Nov 21 '05 #4
You don't have to match it, but whatever lock you use must not be
contrary to the lock used by the other program.

For example, if the other program had opened the file using
FileShare.None, then you would not be able to open the file at all.

FileShare.None means "Open the file and don't allow any other program
to open it for any reason."

FileShare.Read means "Open the file and only allow other programs to
read from the file but not write to it"

FileShare.Write means "Open the file and only allow other programs to
write the file, but not read it."

FileShare.ReadW rite means "Open the file and all other programs to read
from and write to the file."

In general, whoever opens the file first has control over how other
programs can access the file. If the firewall had not allowed read
access, you would not have been able to open the file for reading.

Nov 21 '05 #5

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

Similar topics

2
8279
by: martijn | last post by:
Hi There, my vb app can open files. Well, actually my vb app launches word or excell to open them. These files are shared in a network. If somebody else has allready opened that file, you must get a requester that says the file is temporarily unavaillable because it is edited somewere else.
5
714
by: PM | last post by:
Has anyone found a way to open a file exclusively where it will fail if the file is already open, i have tried the following _FileStream = new FileStream(@"C:\Data.txt", FileMode.Open, FileAccess.ReadWrite, FileShare.None); which does not prevent me from opening the file even if another user has the file open ie Notepad, it will prevent me from saving the file in notepad until i close the file in the app. I can then save changes made in...
14
11095
by: D. Alvarado | last post by:
Hello, I am trying to open a window containing an image and I would like the image to be flush against the window -- i.e. have no padding or border. Can I make this happen with a single call to a window.open function? I would prefer not to create a separate HTML page. So far all I have is the basic var cwin = window.open('images/KJV-THANKS.gif', 'Thanks', 'width=243,height=420,'); cwin.focus();
3
1342
by: Fadi Komati | last post by:
Dear All, I need your help concerning the following. I am openeing a log file for processing (I need to look for certain activities) obviously i keep reading until the end of file. What i need is the following: I need to be able to reload the file in order to read the entries added to the end of the file. Obviouly, i would like the file pointer to be positioned where i stopped reading .
4
29450
by: Marcel Hug | last post by:
Hello NG ! I would like to test, if a file in my subtree is allready in use by an other application. Do anybody know how to get this information ? It is possible to get this information ? Thanks and regards. Marcel Hug
5
3339
by: Brad | last post by:
In several aspx applications I export crytal reports to pdf, xls and doc files and then the aspx page writes the selected export file to the client browser. This all works with one small quirk: When I run any of the web apps on my workstations iis website, the pdf download always produces the "File Download" dialog, even though I have Confirm after Download turned off. When I select to Open the file from this dialog the file opens in...
7
14003
by: emanshu | last post by:
HI all, I an designing an application in C++. i want to open file requested by end user but i want to reflect an error to user if file is already opened by some other application.. will anybody tell me that how to know that the file is already open or closed.. any help is highly appreciated...
18
6720
by: mollyf | last post by:
I just installed SQL Server 2005 on my PC (the developer's edition) yesterday. I have some scripts written by one of my coworkers to create some tables and stored procedures in a database that I've already created on my computer. Whenever I go to open the script file (whose icon shows that it's a SQL Server Query File and I've got the file type set to open with SQLWB - SQL Server Management Studio), the file opens in Notepad instead of...
0
2023
by: bbrewder | last post by:
I am struggling with some MSAccess automation issues. Basically, we have a .Net application that uses MSAccess for reporting (legacy code). We are able to launch MSAccess fine and even work with the MSAccess COM objects to run our reports (using GetObject(<MDB Path>) - see http://support.microsoft.com/default.aspx?scid=kb;en-us;317113&Product=vbNET for info on how to do this). The problem that we are running into is that if our Access...
0
9404
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10168
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9959
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8835
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7381
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5279
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3929
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.