Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TPath.GetTempFileName replies "The directory name is invalid"

TPath.GetTempFileName (which wraps the WinAPI GetTempFileName) replies "The directory name is invalid" when called from an application run by a user who is logged into a domain.

if they use a login that isn't using the domain, it works.

The customer having a problem is in another country and I am also not familiar with how a domain controller's configuration could be changed to avoid this problem.

I assume that since my application is the one that isn't working correctly, I should be getting a temporary file name in a different way.

"run as administrator" doesn't help.

I have directed them to ensure they have full control over the folders mentioned in the TEMP & TMP system environment variables and apparently they do but it still gives the same error.

My application as a Win32 Delphi desktop application but since Windows is the source of the error, I assume this information to be of limited usefulness.

Windows 10 is the OS.

like image 879
X-Ray Avatar asked Dec 24 '22 02:12

X-Ray


1 Answers

TPath.GetTempFileName calls TPath.GetTempPath at the very beginning but does not check it before calling Winapi.Windows.GetTempFileName using the returned path.

It is very likely that the call to TPath.GetTempPath returns an empty or invalid path.

MSDN says:

The GetTempPath function checks for the existence of environment variables in the following order and uses the first path found:

  1. The path specified by the TMP environment variable.
  2. The path specified by the TEMP environment variable.
  3. The path specified by the USERPROFILE environment variable.
  4. The Windows directory.

If it would return the Windows directory, the call wouldn't fail with the said message. So, probably, there is a wrong path in one of those three environment variables.

Your customer should check these variables and validate them, in terms of existence. You say, that the paths are "apparently" okay.

Experience taught me to doubt what customers say they checked... You could make a call to TPath.GetTempPath on your own before calling TPath.GetTempFileName to check if it exists. Alternatively you can call it in case of failure as part of handling the raised exception and add the path to the error message.

like image 133
René Hoffmann Avatar answered Feb 09 '23 00:02

René Hoffmann