1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198:
| unit Unit4;
interface
uses Windows, SysUtils, Classes, Graphics, Forms, Controls, StdCtrls, Buttons, ExtCtrls, IniFiles;
type TAboutBox = class(TForm) Panel1: TPanel; ProgramIcon: TImage; ProductName: TLabel; Version: TLabel; Copyright: TLabel; Comments: TLabel; LizenzLabel: TLabel; KeyLabel: TLabel; Label1: TLabel; Label2: TLabel; procedure Panel1Click(Sender: TObject); procedure FormCreate(Sender: TObject);
function IsAdmin: Boolean; function GetBiosDate: string; function CalcCPUSpeed: Extended;
private public end;
var AboutBox: TAboutBox; ini : TIniFile; Date : TDate;
implementation
{$R *.dfm}
procedure TAboutBox.FormCreate(Sender: TObject); begin Label2.Caption := FloatToStr(CalcCPUSpeed);
if FileExists('C:\Settings\License.lic')=TRUE then begin ini := TIniFile.Create('C:\Settings\License.lic'); try ini.ReadString('Data','Lizenznehmer',LizenzLabel.Caption); ini.ReadString('Data','Key',KeyLabel.Caption); ini.ReadString('Data','Apotheke',Label1.Caption); finally ini.Free; end; end else begin if Application.MessageBox('Das Programm war nicht in der Lage, eine gültige Lizenz zu erkennen.'+ #13+#10+''+ #13+#10+'Möglicherweise ist die Datei nicht vorhanden, oder ist beschädigt. Expandieren Sie die' + #13+#10+'erforderliche Datei über die Kommandozeile und/oder die Graphik von der CD/DVD in das '+ #13+#10+'entsprechende Verzeichnis. Eine LOG-Datei wird erzeugt.','Ungültige oder beschädigte Lizenz',MB_ICONERROR or mb_OK)=IDOK then ini := TIniFile.Create('C:\BtM-Dienst\var\'+DateToStr(Date)+'.log'); try ini.WriteString('GENERAL','KERNEL',''); ini.WriteString('General','WINVER',''); ini.WriteString('PC_INFO','CPUSpeed',''); ini.WriteString('PC_INFO','BIOS_Date',''); ini.WriteString('UAC','IsAdmin','');
finally ini.Free; end; end; end;
procedure TAboutBox.Panel1Click(Sender: TObject); begin close; end;
function IsAdmin: Boolean; const SECURITY_NT_AUTHORITY: TSIDIdentifierAuthority = (Value: (0, 0, 0, 0, 0, 5)); SECURITY_BUILTIN_DOMAIN_RID = $00000020; DOMAIN_ALIAS_RID_ADMINS = $00000220;
var hAccessToken: THandle; ptgGroups: PTokenGroups; dwInfoBufferSize: DWORD; psidAdministrators: PSID; x: Integer; bSuccess: BOOL; begin Result := False; bSuccess:=False; ptgGroups:=nil; psidAdministrators:=nil; try bSuccess := OpenThreadToken(GetCurrentThread, TOKEN_QUERY, True, hAccessToken); if not bSuccess then begin if GetLastError = ERROR_NO_TOKEN then bSuccess := OpenProcessToken(GetCurrentProcess, TOKEN_QUERY, hAccessToken); end; if bSuccess then begin GetMem(ptgGroups, 1024); bSuccess := GetTokenInformation(hAccessToken, TokenGroups, ptgGroups, 1024, dwInfoBufferSize); if bSuccess then begin AllocateAndInitializeSid(SECURITY_NT_AUTHORITY, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, psidAdministrators); {$R-} for x := 0 to ptgGroups.GroupCount - 1 do if EqualSid(psidAdministrators, ptgGroups.Groups[x].Sid) then begin Result := True; Break; end; {$R+} end; end; finally if bSuccess then CloseHandle(hAccessToken); if Assigned(ptgGroups) then FreeMem(ptgGroups); if Assigned(psidAdministrators) then FreeSid(psidAdministrators); end; end;
function GetBiosDate: string; function SegOfsToLinear(Segment, Offset: Word): Integer; begin result := (Segment shl 4) or Offset; end; begin result := string(PChar(Ptr(SegOfsToLinear($F000, $FFF5)))); end;
function CalcCPUSpeed: Extended; const DelayTime = 500; var TimerHi, TimerLo: DWord; PriorityClass, Priority: Integer; begin try PriorityClass := GetPriorityClass(GetCurrentProcess); Priority := GetThreadPriority(GetCurrentThread);
SetPriorityClass(GetCurrentProcess, REALTIME_PRIORITY_CLASS); SetThreadPriority(GetCurrentThread, THREAD_PRIORITY_TIME_CRITICAL); try Sleep(10); asm dw 310Fh mov TimerLo, eax mov TimerHi, edx end; Sleep(DelayTime); asm dw 310Fh sub eax, TimerLo sbb edx, TimerHi mov TimerLo, eax mov TimerHi, edx end; finally SetThreadPriority(GetCurrentThread, Priority); SetPriorityClass(GetCurrentProcess, PriorityClass); end; Result := TimerLo / (1000.0 * DelayTime); except Result := 0; end;
end; |