PDA

View Full Version : CreateFile always return error code (-1) - please help



Gil.Rozenberg
11-17-2014, 04:18 AM
Hello everyone,

I'm trying to write some logging activity to text file using the installscript.
Basically, it's should be a simple task (as seen on InstallShield help)
Here is my code:

logPath = "c:\\";
logFileName = "gil.log";
nvRet = CreateFile ( nvFileHandle, logPath, logFileName);
if ( nvRet < 0) then
NumToStr(nvRetStr,nvRet);
MessageBox("Error(" + nvRetStr + ") - Cannot create log file: " + logPath + logFileName,INFORMATION);
exit;
else
MessageBox("Successfully created log file: " + logPath + logFileName,INFORMATION);
endif;

The problem is that i always get -1 from CreateFile, i've tried to change file location, name, different PC, running in debug and release setup.exe, it always the same... error code -1.
I can't think of anything else which may causing this error, and furthermore - i can't seem to find proper documentation or list of error code and reasons.

Will appreciate any help or suggestions, Gil.

MichaelU
11-17-2014, 10:28 AM
Sometimes you can get a clearer picture of what's taking place on the machine if you use a tool like Process Monitor. Similar information may be available in InstallScript through Err.LastDllError as well.

The one thing that jumps out at me with the path you mention (and is used in the example) is that it likely requires elevated privileges to write to that location. Depending on how your function is invoked, it's possible that it doesn't have the required privileges. By contrast, FOLDER_TEMP shouldn't require extra privileges, so maybe try that instead of "C:\\".