Click here to Skip to main content
15,119,877 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a problem with an app which works fine when the user runs it, but doesn't work when run from "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run".
You can see the app in the "Task manager" doing nothing. The app doesn't have any associated form or window, but as I said before, it works fine if the user runs it manually.
I tried making a little test app. And surprisingly I get the same problem. Only works if you start the app manually. Please, see below:

program Test;
uses Windows, SysUtils;
{$R *.RES}
  aux: integer;
  hf: THandle;
  t: string;
  written: Cardinal;
  hf := CreateFile('TestLog.txt', GENERIC_WRITE, 0, nil, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
    //so, you can see the process during 1 minute in "Task manager"
    for aux := 1 to 60 do begin
      t := DateTimeToStr(Now) + #13#10;
      WriteFile(hf, t[1], Length(t), written, nil);

If you compile and add an entry to the Windows registry, you could check, that it runs, appears about 1 minute in the "Task manager" and dies. But no file was written to disk.
Instead, if you run the app manually, it writes the file perfectly.
I tested changing the "exe" file by another dummy app with a Form and it works!!! Also tried moving to HKCU, but also it didn't work.

Any idea on what is happening??

Thanks in advance,

1 solution

Problem fixed!!
It was just around the path. I am not specifying the full path.
So, when I run the app double-clicking the exe, I don't need to use full path, as the working directory is the same than the app. But, when run from the registry the working path becomes "C:\Documents and Settings\User\Application Data\...", so, the app is running and writting to this folder.
I have tested my app specifying the full path for all the files and it works fine!!!

Thanks to mdixon7610 from DelphiPages,

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900