Hi,
I've written a program in environment DELPHI 7. This file is inserted in a launcher that I've sent to my client; he has installed then the file.exe on its computer (SO: VISTA/7).
My procedure works leaning to a simple text.file, but it must be before created at root (usually, "C:\").
The host SO prevent my file.exe to create the text.file to work, with the error message "Unable to write c:\File.Txt".
This problem probably derives by the system of writing permissions in the host SO, but by choice, the client don't must modify this system manually for me.
How can I bypass the Windows protection?
- don't write on C: and where?;
- create a new sub-folder free of limit: in which folder?;
- vary one key in HKLM: which?;
- install a .bat file: and it have permissions?;
My installer creates an icon on the desktop to launch the .exe file: in the .pif file, can I insert switches to ask SO that the permissions the .exe file to create/write files on the disk?
I've read many posts, but no contains solution for my problem.
I hope I was clear.

Dani AI

Generated

Windows Vista / 7 will block non‑elevated programs from creating files in protected locations such as the root of C: or Program Files. Trying to "bypass" that protection with registry hacks, .bat wrappers, or PIF tricks is unsafe and unreliable. 's suggestion to use the user's home area is sound; a more robust approach is to resolve the appropriate special folder (AppData, LocalAppData, Documents) with the Shell API and write there, or to have the installer create a machine-wide folder under ProgramData with the correct ACLs.

A simple Delphi 7 pattern (SHGetFolderPath + create folder + save text) — replace "MyAppName" and handle exceptions as needed:

uses
  Windows, ShlObj, SysUtils, Classes;

function GetFolder(CSIDL: Integer): string;
var
  buf: array[0..MAX_PATH] of Char;
begin
  if SHGetFolderPath(0, CSIDL, 0, 0, buf) = S_OK then
    Result := IncludeTrailingPathDelimiter(buf)
  else
    Result := '';
end;

// usage
var
  folder, fname: string;
  SL: TStringList;
begin
  folder := GetFolder(CSIDL_LOCAL_APPDATA); // or CSIDL_APPDATA, CSIDL_PERSONAL
  folder := folder + 'MyAppName\';
  if not DirectoryExists(folder) then
    if not ForceDirectories(folder) then
      raise Exception.Create('Cannot create folder: ' + folder);
  fname := folder + 'File.Txt';
  SL := TStringList.Create;
  try
    SL.Text := 'sample';
    SL.SaveToFile(fname);
  finally
    SL.Free;
  end;
end;

Notes and troubleshooting:

  • Use CSIDL_LOCAL_APPDATA or CSIDL_APPDATA for per‑user data, CSIDL_PERSONAL for Documents, and CSIDL_COMMON_APPDATA (ProgramData) for shared data created at install time. Do not rely on VirtualStore.
  • If a file must live in a machine location, have the installer (which runs elevated) create the folder and set ACLs; do not try to set HKLM keys at runtime to circumvent UAC.
  • If elevation is required, include a manifest (or run an elevated installer) rather than asking users to change system settings.
  • Quick tests: attempt writing to %TEMP% or %LOCALAPPDATA% to confirm it is a permission issue, and capture exceptions so the installer or app can log the real error for support.

This approach keeps the app compatible with Vista/7 security and avoids asking the client to modify system policies.

You could use the values of the environment variables HOMEDRIVE and HOMEPATH to get the location of the user's home directory then create the file in a folder under that, perhaps in "Documents"

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.