Recent

Author Topic: Writing to a file after Windows Startup  (Read 4765 times)

joaowiciuk

  • New Member
  • *
  • Posts: 10
Writing to a file after Windows Startup
« on: October 13, 2011, 05:38:43 am »
Hello everybody, I would like to create a Windows application that writes data to a text file after booting the operating system. I already have the keys entered in the registry, but when the system starts my application can not write the specified file. Any suggestions?  :)

I used the code below:

(...)
AssignFile (File1, 'log.txt');
Rewrite (File1);
Write (File1, 'Hello World!');
Flush (File1);
CloseFile (File1);
(...)

Note: I've tried to use a TStringList to write the file, but I have the same problem.  >:(

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Writing to a file after Windows Startup
« Reply #1 on: October 13, 2011, 10:51:19 am »
How do you determine that "application can not write the specified file"? You can't find the file or you get an error message? What error?

'log.txt' doesn't include the full path so many things may affect to where its trying to save to.

How early must this app be executed? If it should run when user logins to Windows, simpler way to make app start is placing its shortcut in Start-menus Startup folder. That way you don't need registry things.

joaowiciuk

  • New Member
  • *
  • Posts: 10
Re: Writing to a file after Windows Startup
« Reply #2 on: October 13, 2011, 04:15:46 pm »
I do not get any error, but I know that the file is not being recorded because it simply is not created in the same folder of the program.

I will try to put it in the Startup folder and see what happens.

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Writing to a file after Windows Startup
« Reply #3 on: October 13, 2011, 04:27:19 pm »
I already have the keys entered in the registry, but when the system starts my application can not write the specified file. Any suggestions? 

Maybe the registry keys in question are wrong? It might help to show what registry keys you changed (and to what).

Does your application write stuff to log.txt if you call it normally?

What happens if you write a simple batch command that does something like this (untested):
Code: [Select]
echo This is some text > log.txt
... and call that using those registry keys?
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

joaowiciuk

  • New Member
  • *
  • Posts: 10
Re: Writing to a file after Windows Startup
« Reply #4 on: October 13, 2011, 04:52:07 pm »
If i call my application normally it writes to the text file.

Thank you all but I got what I wanted. I simply created a shortcut to my application in the startup folder of windows. Now I will create a sort of installer that does it automatically. Thanks again to everyone, very helpful.  :D

 

TinyPortal © 2005-2018