Solved

ERROR_SHARING_VIOLATION when trying to read timestamp from network shared file

Posted on 2010-11-18
3
781 Views
Last Modified: 2012-05-10
I have to show the timestamp (change time) für an EXE within the program, and this works if the file ist called from the local hard drive. When called from a network share, I receive an error. When examining the "properties" of the shared file, I am owner, and I have full access.

This is the code:
STDMETHODIMP CKonfiguration::GetFileChangeTime(/*[in]*/ BSTR bsDateiMitPfad, /*[out]*/ BSTR * bsZeitstempel)
{
	*bsZeitstempel = NULL;

	// unsinnigen Dateinamen abfangen
	if (SysStringLen(bsDateiMitPfad) <= 1)
		return S_FALSE;

	HANDLE hFile = CreateFile(bsDateiMitPfad, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
	DWORD dwLastError = GetLastError();

	if (hFile == INVALID_HANDLE_VALUE)
	{
		return S_FALSE;
	}

	FILETIME ftCreationTime, ftLastAccessTime, ftLastWriteTime, ftLocal;
	BOOL bSuccess = GetFileTime(hFile, &ftCreationTime, &ftLastAccessTime, &ftLastWriteTime);
	dwLastError = GetLastError();
	CloseHandle(hFile);

Open in new window


CreateFile gives me INVALID_HANDLE_VALUE, and the LastError is ERROR_SHARING_VIOLATION. The call is from within the EXE herself, she tries to find out her own timestamp. GetFileTime must be called with a file handle opened with GENERIC_READ says the documentation, so this is no point for further fiddling.

The server where the share is physically located is a Windows Server 2003 and in the same domain as the client accessing it.

This is VB6, but I had to put it into the .NET zone, because there is no other fitting any more :-(

Any ideas ?
0
Comment
Question by:PC-Alex
3 Comments
 
LVL 37

Expert Comment

by:TommySzalapski
Comment Utility
Are you sure the path in bsDateiMitPfad is correct when you pull it off the network share?
You are using a mapped drive, right?
0
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 500 total points
Comment Utility
Does this cure it?
HANDLE hFile = CreateFile(bsDateiMitPfad, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);





From the help files about CreateFile:

Windows Server 2003 and Windows XP/2000:  A sharing violation occurs if an attempt is made to open a file or directory for deletion on a remote computer when the value of the dwDesiredAccess parameter is the DELETE access flag OR'ed with any other access flag, and the remote file or directory has not been opened with FILE_SHARE_DELETE. To avoid the sharing violation in this scenario, open the remote file or directory with the DELETE access right only, or call DeleteFile without first opening the file or directory for deletion.

I suggest you play a little with the settings - even if you open it with the DELETE rights then you don't actually have to delete it.

0
 
LVL 1

Author Closing Comment

by:PC-Alex
Comment Utility
Yes, that was it, thanks a lot for the fast help
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

762 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

6 Experts available now in Live!

Get 1:1 Help Now