zoukankan      html  css  js  c++  java
  • Delphi获取Windows的版本

    --------------------D7

    ----抄来的,哈哈

    ----------------------------

    ---------------Unit

    unit Unit1;

    interface

    uses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs, StdCtrls,Registry,comobj,ActiveX ;

    type
    TForm1 = class(TForm)
    Edit1: TEdit;
    Button1: TButton;
    Button2: TButton;
    Memo1: TMemo;
    Button3: TButton;
    Button4: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    private
    { Private declarations }
    public
    { Public declarations }
    end;

    var
    Form1: TForm1;

    implementation
    uses WindowsSysVersion;
    {$R *.dfm}

    procedure TForm1.Button1Click(Sender: TObject);
    var
    version:TWinVer;

    TPPrev, TP: TTokenPrivileges;
    TokenHandle: THandle;
    dwRetLen: DWORD;
    lpLuid: TLargeInteger;
    begin

    {OpenProcessToken(GetCurrentProcess, TOKEN_ALL_ACCESS, TokenHandle);
    if (LookupPrivilegeValue(nil, 'SeDebugPrivilege', lpLuid)) then
    begin
    TP.PrivilegeCount := 1;
    TP.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
    TP.Privileges[0].Luid := lpLuid;
    AdjustTokenPrivileges(TokenHandle, False, TP, SizeOf(TPPrev), TPPrev, dwRetLen);
    if GetLastError<>ERROR_SUCCESS then
    ShowMessage('權限獲取失敗!!');
    end;
    CloseHandle(TokenHandle);}

    //if GetSystemDefaultLangID=3082 then
    //Edit1.Text :=IntToStr(GetSystemDefaultLangID) ;
    version:=GetWindowsSystemVersion;
    if version=Win7 then
    begin
    Edit1.Text:='Win7';
    end
    else if version=Win10 then
    begin
    Edit1.Text:='Win10';
    end
    end;

    procedure TForm1.Button2Click(Sender: TObject);
    var
    mm:TRegistry;
    cpu:string;
    begin
    mm:=TRegistry.Create;
    with mm do
    begin
    RootKey:=HKEY_LOCAL_MACHINE;
    if OpenKeyReadOnly('HardwareDescriptionSystemCentralProcessor') then
    begin
    cpu := ReadString('ProcessorNameString');
    Memo1.Lines.Add('处理器:'+cpu);
    end;
    end;
    //Memo1.Lines.Add('系统版本:'+TOSVersion.ToString);
    end;

    function GetWMIProperty(WMIType, WMIProperty: string): string;
    const
    WbemUser ='';
    WbemPassword ='';
    WbemComputer ='localhost';
    var
    FSWbemLocator, FWMIService, FWbemObjectSet, Obj: OleVariant;
    C: Cardinal;
    i,Len:integer;
    tempItem:IEnumVariant;
    count : integer;
    msg : string;
    begin
    try
    result := '';
    FSWbemLocator:= CreateOleObject('WbemScripting.SWbemLocator');
    FWMIService := FSWbemLocator.ConnectServer(WbemComputer, 'rootCIMV2', WbemUser, WbemPassword);
    FWbemObjectSet := FWMIService.ExecQuery('Select * from Win32_' + WMIType);
    tempItem := IEnumVariant(IUnknown(FWbemObjectSet._NewEnum));
    Result:='';
    count := 0;
    while (tempItem.Next(1, obj, c) = S_OK) do
    begin
    Obj := Obj.Properties_.Item(WMIProperty, 0).Value;
    if not VarIsNull(obj) then
    begin
    if(count > 0) then
    result := result + ',';
    Result := Result + trim(Obj);
    Inc(count);
    end;
    end;
    except
    On E : Exception do
    begin
    msg := Format('GetWMIProperty Error,WMIType:%s, WMIProperty:%s, Msg:%s',
    [WMIType, WMIProperty, E.Message ]);//E.ToString
    ShowMessage(msg);
    end;
    end;
    if(lowercase(result) = 'none') then
    result := '';
    end;

    procedure TForm1.Button3Click(Sender: TObject);
    begin
    Edit1.Text:=GetWMIProperty('OperatingSystem', 'Version');
    end;

    procedure wbNewWindow3(ASender: TObject; var ppDisp: IDispatch;
    var Cancel: WordBool; dwFlags: Cardinal; const bstrUrlContext,
    bstrUrl: WideString);
    begin
    // dwFlags <=4 for auto popup
    Cancel := dwFlags <= 4;
    end;

    end.

    --------------------unit结束

    -----------Form

    object Form1: TForm1
    Left = 549
    Top = 280
    Width = 523
    Height = 410
    Caption = '获取操作系统版本'
    Color = clBtnFace
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -11
    Font.Name = 'MS Sans Serif'
    Font.Style = []
    OldCreateOrder = False
    PixelsPerInch = 96
    TextHeight = 13
    object Edit1: TEdit
    Left = 40
    Top = 32
    Width = 257
    Height = 21
    ImeName = '中文(简体) - 搜狗拼音输入法'
    TabOrder = 0
    end
    object Button1: TButton
    Left = 72
    Top = 80
    Width = 97
    Height = 25
    Caption = '获取Win版本'
    TabOrder = 1
    Visible = False
    OnClick = Button1Click
    end
    object Button2: TButton
    Left = 24
    Top = 144
    Width = 75
    Height = 25
    Caption = 'Button2'
    Constraints.MaxHeight = 25
    Constraints.MaxWidth = 75
    Constraints.MinHeight = 25
    Constraints.MinWidth = 75
    TabOrder = 2
    Visible = False
    OnClick = Button2Click
    end
    object Memo1: TMemo
    Left = 16
    Top = 120
    Width = 185
    Height = 17
    ImeName = '中文(简体) - 搜狗拼音输入法'
    Lines.Strings = (
    'Memo1')
    TabOrder = 3
    Visible = False
    end
    object Button3: TButton
    Left = 200
    Top = 80
    Width = 105
    Height = 25
    Caption = '获取版本号'
    TabOrder = 4
    OnClick = Button3Click
    end
    object Button4: TButton
    Left = 256
    Top = 320
    Width = 75
    Height = 25
    Caption = 'Button4'
    TabOrder = 5
    end
    end

    ------------------Form结束

  • 相关阅读:
    解决pydev无法增加jython271 interpreter的问题
    使用pygal 做chart图的经验分享
    python4delphi 使用
    Some Delphi tips
    http request method and response codes
    flask 项目的开发经验总结
    解决pydev报unsolved import的问题
    python __future__ package的几个特性
    用一个简单的例子来理解python高阶函数
    正确地组织python项目的结构
  • 原文地址:https://www.cnblogs.com/dmqhjp/p/14626577.html
Copyright © 2011-2022 走看看