str := '';
case verInfo.dwPlatformId of
VER_PLATFORM_WIN32s : str := 'Win16 running Win32s';
VER_PLATFORM_WIN32_WINDOWS : str := 'Win32 Windows, probably Win95';
VER_PLATFORM_WIN32_NT : str := 'WinNT, full 32-bit';
end;
Memo1.Lines.Add(str);
str := '';
for I := 0 to 127 do
str := str + verInfo.szCSDVersion[I];
Memo1.Lines.Add(str);
end
end;
////////////////////////////////////////////////////////////////////////////
constructor TOperatingSystem.Create;
begin
inherited;
end;
destructor TOperatingSystem.Destroy;
begin
inherited;
end;
procedure TOperatingSystem.GetInfo;
var
OK: Boolean;
const
rkOSInfo95 = {HKEY_LOCAL_MACHINE}'SOFTWAREMicrosoftWindowsCurrentVersion';
rkOSInfoNT = {HKEY_LOCAL_MACHINE}'SOFTWAREMicrosoftWindows NTCurrentVersion';
rvProductID = 'ProductID';
rvProductKey = 'ProductKey';
begin
FProductID:='';
with TRegistry.create do begin
rootkey:=HKEY_LOCAL_MACHINE;
if OK then begin
if ValueExists(rvProductID) then
FProductID:=ReadString(rvProductID);
if ValueExists(rvProductKey) then
FProductKey:=ReadString(rvProductKey);
CloseKey;
end;
Free;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
OS_INFO : TOperatingSystem;
begin
OS_INFO := TOperatingSystem.Create;
OS_INFO.GetInfo;
Memo1.Lines.Add(OS_INFO.ProductID);
Memo1.Lines.Add(OS_INFO.ProductKey);
OS_INFO.Destroy;
end;
hsr///////////////////////////////////////////////////////////////////
아래 예제는 버튼1은 os버젼을 버튼2는 id와 key를 가져오는건데요
두개를 잘 혼용해서 여러운영체제에 적합하게 만들면 될겁니다..
id와 key는 래지스트리를 읽어오는겁니다.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TOperatingSystem = class(TPersistent)
private
FProductID: string;
FProductKey: string;
protected
public
constructor Create;
destructor Destroy; override;
procedure GetInfo;
published
property ProductID :string read FProductID {$IFNDEF D6PLUS} write FProductID {$ENDIF} stored false;
property ProductKey :string read FProductKey {$IFNDEF D6PLUS} write FProductKey {$ENDIF} stored False;
end;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
uses
Registry{$IFDEF D6PLUS}, StrUtils {$ENDIF};
procedure TForm1.Button1Click(Sender: TObject);
var
verInfo : TOSVERSIONINFO;
str : String;
I : Word;
begin
verInfo.dwOSVersionInfoSize := SizeOf(TOSVersionInfo);
if GetVersionEx(verInfo) then begin
Memo1.Lines.Add(IntToStr(verInfo.dwOSVersionInfoSize));
Memo1.Lines.Add(IntToStr(verInfo.dwMajorVersion));
Memo1.Lines.Add(IntToStr(verInfo.dwMinorVersion));
Memo1.Lines.Add(IntToStr(verInfo.dwBuildNumber));
str := '';
case verInfo.dwPlatformId of
VER_PLATFORM_WIN32s : str := 'Win16 running Win32s';
VER_PLATFORM_WIN32_WINDOWS : str := 'Win32 Windows, probably Win95';
VER_PLATFORM_WIN32_NT : str := 'WinNT, full 32-bit';
end;
Memo1.Lines.Add(str);
str := '';
for I := 0 to 127 do
str := str + verInfo.szCSDVersion[I];
Memo1.Lines.Add(str);
end
end;
////////////////////////////////////////////////////////////////////////////
constructor TOperatingSystem.Create;
begin
inherited;
end;
destructor TOperatingSystem.Destroy;
begin
inherited;
end;
procedure TOperatingSystem.GetInfo;
var
OK: Boolean;
const
rkOSInfo95 = {HKEY_LOCAL_MACHINE}'SOFTWAREMicrosoftWindowsCurrentVersion';
rkOSInfoNT = {HKEY_LOCAL_MACHINE}'SOFTWAREMicrosoftWindows NTCurrentVersion';
rvProductID = 'ProductID';
rvProductKey = 'ProductKey';
begin
FProductID:='';
with TRegistry.create do begin
rootkey:=HKEY_LOCAL_MACHINE;
OK:=OpenKeyReadOnly(rkOSInfoNT);
//OK:=OpenKeyReadOnly(rkOSInfo95);
if OK then begin
if ValueExists(rvProductID) then
FProductID:=ReadString(rvProductID);
if ValueExists(rvProductKey) then
FProductKey:=ReadString(rvProductKey);
CloseKey;
end;
Free;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
OS_INFO : TOperatingSystem;
begin
OS_INFO := TOperatingSystem.Create;
OS_INFO.GetInfo;
Memo1.Lines.Add(OS_INFO.ProductID);
Memo1.Lines.Add(OS_INFO.ProductKey);
OS_INFO.Destroy;
end;