home *** CD-ROM | disk | FTP | other *** search
- program autorun;
-
- uses
- Forms,
- SysUtils, Windows, ShellAPI,
- MainForm in 'MainForm.pas' {MainForm1},
- AboutForm in 'AboutForm.pas' {AboutForm1},
- HelpForm in 'HelpForm.pas' {HelpForm1},
- ShortCutForm in 'ShortCutForm.pas' {ShortCutForm1},
- ErrorForm in 'ErrorForm.pas' {ErrorForm1},
- EventForm in 'EventForm.pas' {EventForm1};
-
- {$R *.RES}
- {$R icons.res}
-
- const
- UniqueAppString : PChar = 'AutoRun 1.0 by Hadraba-Soft';
- MutexHandle : THandle = 0;
-
- var
- S : String;
- OrgExitProc : Pointer;
- MessageID : Integer;
- WProc : TFNWndProc = nil;
- BSMRecipients : dWord;
- i : LongInt;
-
- function BroadcastSystemMessage(Flags: DWORD; Recipients: PDWORD;
- uiMessage: UINT; wParam: WPARAM; lParam: LPARAM): Longint; stdcall;
- external user32 name 'BroadcastSystemMessage';
-
- function NewWndProc(Handle : hWnd; Msg : Integer; wParam,
- lParam : LongInt) : LongInt; stdcall;
- begin
- Result := 0;
- If Msg = MessageID then
- begin
- If IsIconic(Application.Handle) then
- begin
- Application.MainForm.WindowState := wsNormal;
- Application.Restore;
- end;
- SetForegroundWindow(Application.MainForm.Handle);
- end
- else
- Result := CallWindowProc(WProc, Handle, Msg, wParam, lParam);
- end;
-
- procedure HaltApplication; far;
- begin
- ExitProc := OrgExitProc;
- ReleaseMutex(MutexHandle);
- Halt(ExitCode);
- end;
-
- begin
- OrgExitProc := ExitProc;
- ExitProc := @HaltApplication;
- MessageID := RegisterWindowMessage(UniqueAppString);
- If ParamCount > 0 then
- begin
- For i := 1 to ParamCount do
- begin
- If ParamStr(i) = ':' then
- ShellExecute(0, 'open', PChar(ExtractFileDrive(ParamStr(0))), '', '',
- SW_Normal)
- else
- begin
- If ShellExecute(0, 'open', PChar(ParamStr(i)), '', '',
- SW_Normal) <= 32 then
- MessageBox(0, PChar('Can''t open ' + ParamStr(i) +
- '. Operation aborted.'), 'AutoRun Version 1.0',
- mb_IconExclamation or mb_Ok);
- end;
- end;
- Halt(0);
- end;
- If OpenMutex(Mutex_All_Access, False, UniqueAppString) = 0 then
- begin
- MutexHandle := CreateMutex(nil, False, UniqueAppString);
- WProc := TFNWndProc(SetWindowLong(Application.Handle,
- gwl_WndProc, LongInt(@NewWndProc)));
- Application.Initialize;
- Application.Title := 'AutoRun Version 1.0';
- CDDrive := ExtractFileDrive(ParamStr(0));
- IniFileName := ExtractFilePath(ParamStr(0)) +
- ExtractFileName(ParamStr(0));
- S := ExtractFileExt(ParamStr(0));
- SetLength(IniFileName, Length(IniFileName) - Length(S));
- IniFileName := IniFileName + '.ini';
- FillInfo(CDVName, CDVSerial);
- If FileSearch(IniFileName, '') = '' then
- begin
- Application.CreateForm(THelpForm1, HelpForm1);
- Application.CreateForm(TAboutForm1, AboutForm1);
- end
- else
- begin
- Application.CreateForm(TMainForm1, MainForm1);
- Application.CreateForm(TAboutForm1, AboutForm1);
- Application.CreateForm(THelpForm1, HelpForm1);
- Application.CreateForm(TShortCutForm1, ShortCutForm1);
- Application.CreateForm(TErrorForm1, ErrorForm1);
- Application.CreateForm(TEventForm1, EventForm1);
- end;
- Application.Run;
- end
- else
- begin
- BSMRecipients := bsm_Applications;
- BroadCastSystemMessage(bsf_IgnoreCurrentTask or bsf_PostMessage,
- @BSMRecipients, MessageID, 0, 0);
- end;
- end.
-
-