Link to home
Start Free TrialLog in
Avatar of PC-Alex
PC-Alex

asked on

ERROR_SHARING_VIOLATION when trying to read timestamp from network shared file

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 ?
Avatar of TommySzalapski
TommySzalapski
Flag of United States of America image

Are you sure the path in bsDateiMitPfad is correct when you pull it off the network share?
You are using a mapped drive, right?
ASKER CERTIFIED SOLUTION
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of PC-Alex
PC-Alex

ASKER

Yes, that was it, thanks a lot for the fast help