2004. augusztus 11., szerda

How to know if your application is running in SafeMode


Problem/Question/Abstract:

Sometimes an application uses resources that doesn�t exist when windows is running in SafeMode, so how do you detect this situation?

Answer:

Use Windows API GetSystemMetrics with SM_CLEANBOOT parameter, this specifies how the system was started, in your project�s code use:

program Project1;

uses
  Forms,
  Windows,
  Dialogs,
  Unit1 in 'Unit1.pas' {Form1};

{$R *.RES}

begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);

  case GetSystemMetrics(SM_CLEANBOOT) of
    1:
      begin
        ShowMessage('Running in Safe Mode: Fail-Safe Boot');
        Application.Terminate;
      end;
    2:
      begin
        ShowMessage('Running in Safe Mode: Fail-safe with network boot');
        Application.Terminate;
      end;
  end;

  Application.Run;
end.

This way you can prevent the user to use your application and avoid havoc!

Nincsenek megjegyzések:

Megjegyzés küldése