Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

running code just after rebooting

Hi;

i have to run some code to make some changes (initialize some flags) in my access table just after restarting the computer before nobody can use the application. How is it possible?

Thank you.

Comments

  • softmansoftman Posts: 157Member
    : Hi;
    :
    : i have to run some code to make some changes (initialize some flags) in my access table just after restarting the computer before nobody can use the application. How is it possible?
    :
    : Thank you.
    :
    Hi!

    Just simply register it in the windows registry :
    HKEY_CURRENT_USER\SoftwareMicrosoftWindowsCurrentVersionRunOnce
    with your setup wizard, or you can find a delphi sample in the help files, how can you register it with delphi code:

    The following example shows how to tell Windows to relaunch your application when Windows starts up if it was running when the system shut down. When Windows starts up, it launches each application listed in the RunOnce key and then deletes the entry for that application. Therefore, you do not need to remove the entry written here.
    [code]
    procedure TForm1.WMEndSession(var Message: TWMEndSession);
    var
    Reg: TRegistry;
    begin
    Reg := TRegistry.Create;
    try
    Reg.RootKey := HKEY_CURRENT_USER;
    if Reg.OpenKey('SoftwareMicrosoftWindowsCurrentVersionRunOnce', True) then
    begin
    Reg.WriteString('MyApp','"' + ParamStr(0) + '"');
    Reg.CloseKey;
    end;
    finally
    Reg.Free;
    inherited;
    end;

    end;
    [/code]

    In order for this method to be called, it must be declared in your main form class as follows:
    [code]
    private

    procedure WMEndSession(var Msg:TWMEndSession); message WM_ENDSESSION;
    [/code]
    SoftMan

  • softmansoftman Posts: 157Member
    : : Hi;
    : :
    : : i have to run some code to make some changes (initialize some flags) in my access table just after restarting the computer before nobody can use the application. How is it possible?
    : :
    : : Thank you.
    : :
    : Hi!
    :
    : Just simply register it in the windows registry :
    : HKEY_CURRENT_USER\SoftwareMicrosoftWindowsCurrentVersionRunOnce
    : with your setup wizard, or you can find a delphi sample in the help files, how can you register it with delphi code:
    :
    : The following example shows how to tell Windows to relaunch your application when Windows starts up if it was running when the system shut down. When Windows starts up, it launches each application listed in the RunOnce key and then deletes the entry for that application. Therefore, you do not need to remove the entry written here.
    : [code]
    : procedure TForm1.WMEndSession(var Message: TWMEndSession);
    : var
    : Reg: TRegistry;
    : begin
    : Reg := TRegistry.Create;
    : try
    : Reg.RootKey := HKEY_CURRENT_USER;
    : if Reg.OpenKey('SoftwareMicrosoftWindowsCurrentVersionRunOnce', True) then
    : begin
    : Reg.WriteString('MyApp','"' + ParamStr(0) + '"');
    : Reg.CloseKey;
    : end;
    : finally
    : Reg.Free;
    : inherited;
    : end;
    :
    : end;
    : [/code]
    :
    : In order for this method to be called, it must be declared in your main form class as follows:
    : [code]
    : private
    :
    : procedure WMEndSession(var Msg:TWMEndSession); message WM_ENDSESSION;
    : [/code]
    : SoftMan
    :
    :
    I'v Nearly forgot to say, that if you dont want to run it only once, eg. after installation, then register it to:
    HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionRun
    SoftMan

  • _yilmaz_yilmaz Posts: 150Member
    Hi;
    thanx but i could not run it.
    First of all i couldn't find which unit to include for TWMEndSession.
    Secondly, should i call this somewhere, or is it enough to add only this code?
    Third, is this code enough for registry? what is HKEY_CURRENT_USER\SoftwareMicrosoftWindowsCurrentVersionRunOnce and where is it registered?
    Thanx.


    : : : Hi;
    : : :
    : : : i have to run some code to make some changes (initialize some flags) in my access table just after restarting the computer before nobody can use the application. How is it possible?
    : : :
    : : : Thank you.
    : : :
    : : Hi!
    : :
    : : Just simply register it in the windows registry :
    : : HKEY_CURRENT_USER\SoftwareMicrosoftWindowsCurrentVersionRunOnce
    : : with your setup wizard, or you can find a delphi sample in the help files, how can you register it with delphi code:
    : :
    : : The following example shows how to tell Windows to relaunch your application when Windows starts up if it was running when the system shut down. When Windows starts up, it launches each application listed in the RunOnce key and then deletes the entry for that application. Therefore, you do not need to remove the entry written here.
    : : [code]
    : : procedure TForm1.WMEndSession(var Message: TWMEndSession);
    : : var
    : : Reg: TRegistry;
    : : begin
    : : Reg := TRegistry.Create;
    : : try
    : : Reg.RootKey := HKEY_CURRENT_USER;
    : : if Reg.OpenKey('SoftwareMicrosoftWindowsCurrentVersionRunOnce', True) then
    : : begin
    : : Reg.WriteString('MyApp','"' + ParamStr(0) + '"');
    : : Reg.CloseKey;
    : : end;
    : : finally
    : : Reg.Free;
    : : inherited;
    : : end;
    : :
    : : end;
    : : [/code]
    : :
    : : In order for this method to be called, it must be declared in your main form class as follows:
    : : [code]
    : : private
    : :
    : : procedure WMEndSession(var Msg:TWMEndSession); message WM_ENDSESSION;
    : : [/code]
    : : SoftMan
    : :
    : :
    : I'v Nearly forgot to say, that if you dont want to run it only once, eg. after installation, then register it to:
    : HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionRun
    : SoftMan
    :
    :

  • zibadianzibadian Posts: 6,349Member
    : Hi;
    : thanx but i could not run it.
    : First of all i couldn't find which unit to include for TWMEndSession.
    : Secondly, should i call this somewhere, or is it enough to add only this code?
    : Third, is this code enough for registry? what is HKEY_CURRENT_USER\SoftwareMicrosoftWindowsCurrentVersionRunOnce and where is it registered?
    : Thanx.
    :
    :
    : : : : Hi;
    : : : :
    : : : : i have to run some code to make some changes (initialize some flags) in my access table just after restarting the computer before nobody can use the application. How is it possible?
    : : : :
    : : : : Thank you.
    : : : :
    : : : Hi!
    : : :
    : : : Just simply register it in the windows registry :
    : : : HKEY_CURRENT_USER\SoftwareMicrosoftWindowsCurrentVersionRunOnce
    : : : with your setup wizard, or you can find a delphi sample in the help files, how can you register it with delphi code:
    : : :
    : : : The following example shows how to tell Windows to relaunch your application when Windows starts up if it was running when the system shut down. When Windows starts up, it launches each application listed in the RunOnce key and then deletes the entry for that application. Therefore, you do not need to remove the entry written here.
    : : : [code]
    : : : procedure TForm1.WMEndSession(var Message: TWMEndSession);
    : : : var
    : : : Reg: TRegistry;
    : : : begin
    : : : Reg := TRegistry.Create;
    : : : try
    : : : Reg.RootKey := HKEY_CURRENT_USER;
    : : : if Reg.OpenKey('SoftwareMicrosoftWindowsCurrentVersionRunOnce', True) then
    : : : begin
    : : : Reg.WriteString('MyApp','"' + ParamStr(0) + '"');
    : : : Reg.CloseKey;
    : : : end;
    : : : finally
    : : : Reg.Free;
    : : : inherited;
    : : : end;
    : : :
    : : : end;
    : : : [/code]
    : : :
    : : : In order for this method to be called, it must be declared in your main form class as follows:
    : : : [code]
    : : : private
    : : :
    : : : procedure WMEndSession(var Msg:TWMEndSession); message WM_ENDSESSION;
    : : : [/code]
    : : : SoftMan
    : : :
    : : :
    : : I'v Nearly forgot to say, that if you dont want to run it only once, eg. after installation, then register it to:
    : : HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionRun
    : : SoftMan
    : :
    : :
    :
    :
    You can also use the OnClose() event instead of the WMEndSession message.
    The HKEY_CURRENT_USER\SoftwareMicrosoftWindowsCurrentVersionRunOnce is a combination of a constant (HKEY_CURRENT_USER) in the Registry unit and a string (the rest), which you supply. It describes the registry path underwhich you want to place the value of your program. See the TRegistry object for more info.
  • softmansoftman Posts: 157Member
    : : Hi;
    : : thanx but i could not run it.
    : : First of all i couldn't find which unit to include for TWMEndSession.
    : : Secondly, should i call this somewhere, or is it enough to add only this code?
    : : Third, is this code enough for registry? what is HKEY_CURRENT_USER\SoftwareMicrosoftWindowsCurrentVersionRunOnce and where is it registered?
    : : Thanx.
    : :
    : :
    : : : : : Hi;
    : : : : :
    : : : : : i have to run some code to make some changes (initialize some flags) in my access table just after restarting the computer before nobody can use the application. How is it possible?
    : : : : :
    : : : : : Thank you.
    : : : : :
    : : : : Hi!
    : : : :
    : : : : Just simply register it in the windows registry :
    : : : : HKEY_CURRENT_USER\SoftwareMicrosoftWindowsCurrentVersionRunOnce
    : : : : with your setup wizard, or you can find a delphi sample in the help files, how can you register it with delphi code:
    : : : :
    : : : : The following example shows how to tell Windows to relaunch your application when Windows starts up if it was running when the system shut down. When Windows starts up, it launches each application listed in the RunOnce key and then deletes the entry for that application. Therefore, you do not need to remove the entry written here.
    : : : : [code]
    : : : : procedure TForm1.WMEndSession(var Message: TWMEndSession);
    : : : : var
    : : : : Reg: TRegistry;
    : : : : begin
    : : : : Reg := TRegistry.Create;
    : : : : try
    : : : : Reg.RootKey := HKEY_CURRENT_USER;
    : : : : if Reg.OpenKey('SoftwareMicrosoftWindowsCurrentVersionRunOnce', True) then
    : : : : begin
    : : : : Reg.WriteString('MyApp','"' + ParamStr(0) + '"');
    : : : : Reg.CloseKey;
    : : : : end;
    : : : : finally
    : : : : Reg.Free;
    : : : : inherited;
    : : : : end;
    : : : :
    : : : : end;
    : : : : [/code]
    : : : :
    : : : : In order for this method to be called, it must be declared in your main form class as follows:
    : : : : [code]
    : : : : private
    : : : :
    : : : : procedure WMEndSession(var Msg:TWMEndSession); message WM_ENDSESSION;
    : : : : [/code]
    : : : : SoftMan
    : : : :
    : : : :
    : : : I'v Nearly forgot to say, that if you dont want to run it only once, eg. after installation, then register it to:
    : : : HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionRun
    : : : SoftMan
    : : :
    : : :
    : :
    : :
    : You can also use the OnClose() event instead of the WMEndSession message.
    : The HKEY_CURRENT_USER\SoftwareMicrosoftWindowsCurrentVersionRunOnce is a combination of a constant (HKEY_CURRENT_USER) in the Registry unit and a string (the rest), which you supply. It describes the registry path underwhich you want to place the value of your program. See the TRegistry object for more info.
    :

    -Actually, the TWMEndSession is in unit "Messages" The main difference between TWMEndSession and OnClose event, is that TWMEndSession occures, if windows terminates your program by a shoutdown, or reboot. So your code will be invoked, if your application runing while you turn off your computer. OnClose event occures, when you close the form. So up to you to decide wich one to use. If you want to register it only once, you dont have to use any of them, only invoke the code once.
    -It is registered in Windows Registry. You also can add your registry by manually runing "regedit" from commandline. As mentioned above, you can find more info in the help files.
    SoftMan

Sign In or Register to comment.