Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

ERROR_SHARING_VIOLATION when trying to read timestamp from network shared file

Posted on 2010-11-18
3
Medium Priority
?
891 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
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 45

Accepted Solution

by:
AndyAinscow earned 2000 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

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

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

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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

580 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