Share via

Much slower performance accessing network shared files when starting App from Administrator mode

Angelo Wang 0 Reputation points
2023-01-16T05:24:43.37+00:00

Hi there,

We have met quite strange behavior when starting the same application (AutoCAD Civil 3D) from Administrator mode, it shows a much slower performance when we access network sharing paths like \automation_server\some_folder\a.file.

The main APIs we are using is _taccess(), GetFileAttributes(), CreateFile(), GetFileTime().

The problem was found accidentally when we tested performance when working with net share files, and frequent file access does impact the performance. We certainly have a lot of not-needed API calls, but then we start the application from Administrator mode, and it becomes totally unusable - sometimes it looks like a hang although, after 30 minutes, the app can react again. It looks like the net share file access is not cached at all.

The first question is: are there any differences between non-Admin and Admin mode?

And even strangely, if I write some test applications (C#) to call File.Exists() and File.GetLastWriteTime() many times, and the 'cache' seems indeed working. So it looks like it's our own code issue.

Then we found a piece of code like below:

if (::GetFileAttributes(fileName) != INVALID_FILE_ATTRIBUTES) {
    HANDLE hFile = ::CreateFIle(fileName,
                                GENERIC_READ,
                                FILE_SHARE_READ | FILE_SHARE_WRITE,
                                NULL, OPEN_EXISTING, 0, NULL);
    if (hFile != INVALID_HANDLE_VALUE) {
        FILETIME ftCreationTime, ftLastAccessTime, ftLastWriteTime;
        ::GetFileTime(hFile,  &ftCreationTime, &ftLastAccessTime, &ftLastWriteTime);
   }
}

And GetFIleAttributes was called for getting the last write time, which was actually not needed. Then we remove it and it seems the non-Admin and Admin now have the same performance.

So the second question is: is this indeed the reason for causing the non-Admin and Admin difference?

Windows development | Windows API - Win32
0 comments No comments

1 answer

Sort by: Most helpful
  1. Xiaopo Yang - MSFT 12,736 Reputation points Microsoft External Staff
    2023-01-17T02:14:10.8733333+00:00

    According to GetFileTime,

    Not all file systems can record creation and last access times and not all file systems record them in the same manner.

    It depends on file systems. Your call makes the file system update the time instantly.

    And according to How AccessCheck Works, it may take a little bit long, which depends on the file DACL.

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.