Solved

ERROR_SHARING_VIOLATION when trying to read timestamp from network shared file

Posted on 2010-11-18
3
834 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 34170957
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
ID: 34170959
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
ID: 34170963
Yes, that was it, thanks a lot for the fast help
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

734 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