Click here to Skip to main content
15,064,293 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
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}
var
  aux: integer;
  hf: THandle;
  t: string;
  written: Cardinal;
begin
  hf := CreateFile('TestLog.txt', GENERIC_WRITE, 0, nil, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
  try
    //so, you can see the process during 1 minute in "Task manager"
    for aux := 1 to 60 do begin
      Sleep(1000); 
      t := DateTimeToStr(Now) + #13#10;
      WriteFile(hf, t[1], Length(t), written, nil);
    end;
  finally
    CloseHandle(hf);
  end;
end.



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,
VictorVG
Posted

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,
VictorVG
   

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




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