During the use process, we will find that if you write the Exe with Uac into the Run of the registry, it cannot be automatically started upon startup, because the exe with Uac needs to apply for administrator permissions, in order to run the execution program, but cannot apply for administrator permissions at startup, Exe will not be able to start normally. So how to enable the Uac-enabled Exe to automatically start upon startup.
Since the Uac-enabled Exe cannot be applied for administrator permissions, you can create a new mini program without Uac. Can you solve the problem by applying for administrator permissions to start the exe? The implementation method is as follows:
Unit DyjStartMainForm;
Interface
Uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ShellAPI;
Const
WM_STARTCLOSE = wm_user+ 100;
Type
TFrmDyjStart = class (TForm)
Procedure FormCreate (Sender: TObject );
Private
{Private declarations}
Protected
Procedure WMStartClose (var Msg: TMessage); message WM_STARTCLOSE;
Public
{Public declarations}
End;
Var
FrmDyjStart: TFrmDyjStart;
Implementation
{$ R *. dfm}
Procedure TFrmDyjStart. FormCreate (Sender: TObject );
Begin
PostMessage (Self. Handle, WM_STARTCLOSE, 0, 0 );
End;
Procedure TFrmDyjStart. WMStartClose (var Msg: TMessage );
Var
_ VPathExe: string;
Begin
_ VPathExe: = ExtractFilePath (Application. ExeName) + 'sysreset.exe ';
ShellExecute (0, 'runas', PChar (_ vPathExe), nil, nil, SW_SHOWNORMAL );
Application. Terminate;
End;