INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

please, how to add start-up behaviour ?

please, how to add start-up behaviour ?

(OP)
hello, i have an application, and i put a shortcut to it inside win+startup folder, and all is ok.

Now i wish to change this approach, by coding it, and so i have used the code listed at the bottom of this post.
The code inputs a key inside HKLM, but there is a windows error when system starts :

This error is similar on 3 different computers, running win xp or win 7.

Please, i would apreciate a bit of help :) kindly !

procedure SetAutoStart(AppName, AppTitle: string; bRegister: Boolean);
const RegKey = '\Software\Microsoft\Windows\CurrentVersion\Run'; // Run or RunOnce
var Registry: TRegistry;
begin
Registry := TRegistry.Create;
try Registry.RootKey := HKEY_LOCAL_MACHINE;
if Registry.OpenKey(RegKey, False)
then begin
if bRegister = False then Registry.DeleteValue(AppTitle)
else Registry.WriteString(AppTitle, AppName);
end;
finally Registry.Free;
end;
end;

RE: please, how to add start-up behaviour ?

The only think I see missing is the call to CloseKey. Perhaps that is causing the issue.

CODE

procedure SetAutoStart(AppName, AppTitle: string; bRegister: Boolean);
const 
  RegKey = '\Software\Microsoft\Windows\CurrentVersion\Run';
var 
  Registry: TRegistry;
begin
  Registry := TRegistry.Create;
  try
    Registry.RootKey := HKEY_LOCAL_MACHINE;
    if Registry.OpenKey(RegKey, False) then
    try
      if bRegister = False then 
        Registry.DeleteValue(AppTitle)
      else
        Registry.WriteString(AppTitle, AppName);
    finally
      Registry.CloseKey;
    end;
  finally
    Registry.Free;
  end;
end; 

Of course, I don't see what values you are passing to this procedure, so it may also stem from the values you are passing, and there is also a possibility that your program needs some resource from your computer that is not available when it is starting up, which would definitely be causing an Access Violation Error.

RE: please, how to add start-up behaviour ?

(OP)
hello majlumbo :) the program tries to read some data from a file, but it can not read it, even if the file exists.

i have used a 30seconds delay, and after windows started, i also started the application by clicking on it, and it worked. However, after the 30seconds timer, the application started automatically, and same error appeared.

In other words, even if the file is there, the application is not allowed to read it.

it may be something about privileges, etc, but i dont have experience with this kind of things :) kindly !

RE: please, how to add start-up behaviour ?

(OP)
i created another application, that uses ShellExecute, so to run the main application. Same problem appears.

i use FileExist to verify if the file is there; FileExist calls this function "FindFirstFile(lpFileName: PChar; var lpFindFileData: TWIN32FindData): THandle; stdcall;", and this function is behaving differently

when i launch application :
... by clicking its own icon, handle = 1461824, or 1452896 , or 1462696 ( seems to be changing )
... through the application that uses ShellExecute, handle = 4294967295 ( this value does not change )
* although file is always there ...

is like the main application can not check for files, unless i launch it normally ... pfff

RE: please, how to add start-up behaviour ?

(OP)
i used a simple memo.lines.loadfromfile, and it worked only when i launched the application

when i tried to start the application by "ShellExecute", or by "editing the HKLM\RUN", it did not work

there is a status, depending on launch conditions, that does not allow acces to files

RE: please, how to add start-up behaviour ?

Quote:

it may be something about privileges
Where is the file located? You should probably put the file under %APPDATA% under some directory you create for your application.

As to your application's Handle changing. The handle would be expected to change every time you run it, if you get the save value, it is purely by happenstance.

RE: please, how to add start-up behaviour ?

(OP)
hello majlumbo :) the file has a very simple content, and it is inside the application folder

path is currentdir\*.txt

i will share a very simple code pretty soon, so to show what is wrong

RE: please, how to add start-up behaviour ?

(OP)
i should have used full paths

different ways of starting the application are causing it to have different default search directory paths

thank you majlumbo :) it was nice talking to you :)

RE: please, how to add start-up behaviour ?

Glad to help. At least it put you on the correct path to figure it out on your own.

RE: please, how to add start-up behaviour ?

(OP)
nonono, i did not figure it out myself / just the usual : asking all over the forums :)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close