well I’m unable to write file if application Run auto at start-up but when i click normally by double click on application it create file normally even i’m using Wind7UAC.manifest running application as admin. what is wrong ? not getting this WriteLN(‘WriteFile True’); it means issue is with WriteFile
Procedure CFile(FileName: String; imagem: string; Size: DWORD);
var
hFile: THandle;
lpNumberOfBytesWritten: DWORD;
begin
hFile := CreateFile(PChar(FileName), GENERIC_WRITE, FILE_SHARE_WRITE, nil, CREATE_ALWAYS, FILE_ATTRIBUTE_HIDDEN, 0);
if hFile <> INVALID_HANDLE_VALUE then
begin
if Size = INVALID_HANDLE_VALUE then
SetFilePointer(hFile, 0, nil, FILE_BEGIN);
if WriteFile(hFile, imagem[1], Size, lpNumberOfBytesWritten, nil) = true then
WriteLN('WriteFile True');
CloseHandle(hFile);
end else WriteLN('Cannot Create File !');
end;
I suspect the working directory is the Windows directory when you auto start an app. You don’t have permission to write there (unless you disable UAC).
I recommend you use a full absolute path when you open your file rather than a relative path as at present. Use SHGetSpecialFolderPath to find the location of an appropriate folder,