Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8344841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:29:52+00:00 2026-06-09T06:29:52+00:00

I am trying to read a logfile in two different applications at the same

  • 0

I am trying to read a logfile in two different applications at the same time. But CreateFile (http://msdn.microsoft.com/en-us/library/windows/desktop/aa363858%28v=vs.85%29.aspx) with share-mode #FILE_SHARE_READ always fails on the second call with error-code 32: ERROR_SHARING_VIOLATION: – The process cannot access the file because it is being used by another process.

When the logfile is written in modes FILE_SHARE_WRITE or FILE_SHARE_READ | FILE_SHARE_WRITE the file can not be read by any of the two applications only when FILE_SHARE_READ is used for the writer-application and then it only works if the reader-applications use FILE_SHARE_WRITE or FILE_SHARE_READ | #FILE_SHARE_WRITE, not when using #FILE_SHARE_READ. Strange …. Any suggestions?

Thank you very much.

Amendment:

Writer-Application: CreateFile(file,GENERIC_WRITE,FILE_SHARE_READ,0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0)
Reader-Applications: CreateFile(file,GENERIC_READ,FILE_SHARE_READ | FILE_SHARE_WRITE,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0)

Amendment 2:

When using the calls from the first Amendment the 1st Reader-Application can successfully get the filehandle, but the 2nd Reader-Application will fail with ERROR_SHARING_VIOLATION.

Amendment 3: One pointed me to the solution!

The problem was that I used logical Or instead of bitwise Or for the share-mode:
FILE_SHARE_READ Or FILE_SHARE_WRITE = 1 Or 2 = 1, but it should be FILE_SHARE_READ | FILE_SHARE_WRITE = 1 | 2 = 3. So could not work as the Writer-Application required FILE_SHARE_WRITE.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T06:29:54+00:00Added an answer on June 9, 2026 at 6:29 am

    It isn’t strange, but it does forever trip up programmers that the logic is inverted. When a program creates a log file then it only has to specify FILE_SHARE_READ to allow another process to read the file. It however acquired another capability when doing so, it asked for GENERIC_WRITE so it could write the file. No objection from the operating system, it will forever keep that capability until it closes the file.

    What then goes wrong is another process trying to open the file but deny the right to write the file. In other words only specify FILE_SHARE_READ and not FILE_SHARE_WRITE. That cannot work, the first process already acquired the right to write, you cannot jerk the floor mat and say it shouldn’t write to the file. That would be a nasty Denial Of Service attack. So the operating system says no and fails the CreateFile() call.

    The other process must specify FILE_SHARE_WRITE.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to read an RSS and select information using Linq but can't seem to
I'm trying to read data from the WMI Win32_NTLogEvent class, but I only want
I am trying to add a logfile to a program I am making, but
I'm trying to read a log file of log4net: FileStream fs = new FileStream(filePath,
Trying to read headers for a csv file with: reader = csv.DictReader(open(PATH_FILE),skipinitialspace=True) headers =
After trying to read various articles on sending emails with attachments in PHP (I
Im trying to read a column of String values from my DB. Im trying
Iam trying to read a binary file to memory and pass the starting address
I was trying to read a self-extracting zip (located here ftp://ftp.dnr.state.oh.us/OilGas/Download/Production/By_Year/2010Production.exe ) using java
I am trying to read in an XML file that I have saved to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.