AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Win32/Win64 API (native code) Delphi Name des CD-ROM-Laufwerks (zB LITEON LTD163D)
Thema durchsuchen
Ansicht
Themen-Optionen

Name des CD-ROM-Laufwerks (zB LITEON LTD163D)

Ein Thema von Garfield · begonnen am 9. Jan 2005 · letzter Beitrag vom 26. Jan 2005
Antwort Antwort
Alter Mann

Registriert seit: 15. Nov 2003
Ort: Berlin
949 Beiträge
 
Delphi 10.2 Tokyo Professional
 
#1

Re: Name des CD-ROM-Laufwerks (zB LITEON LTD163D)

  Alt 15. Jan 2005, 18:53
Hallo,

Du kannst es ja hiermit versuchen (Beispiel):

Code:
unit wmiCDROM;

interface

uses Windows, Classes, Contnrs, Variants;

  PCDROMDrive = ^TCDROMDrive;
  TCDROMDrive = class(TObject)
  private
    FUserName         : String;
    FUserPwd          : String;
    FComputerName     : String;

    FDescription      : String;
    FDrive            : String;
    FManufacturer     : String;
    FMediaLoaded      : Boolean;
    FMediaType        : String;
    FName             : String;
    FSCSIBus          : Uint;
    FSCSILogicalUnit  : Uint;
    FSCSIPort         : Uint;
    FSCSITargetId     : Uint;
    FStatus           : String;
  protected
    procedure SystemValues(CDROMDeviceID : String);
  public
    constructor Create(CDROMDeviceID : String);
    destructor Destroy; override;
    property Description    : String read FDescription;
    property Drive          : String read FDrive;
    property Manufacturer   : String read FManufacturer;
    property MediaLoaded    : Boolean read FMediaLoaded default False;
    property MediaType      : String read FMediaType;
    property Name           : String read FName;
    property SCSIBus        : Uint read FSCSIBus;
    property SCSILogicalUnit : Uint read FSCSILogicalUnit;
    property SCSIPort       : Uint read FSCSIPort;
    property SCSITargetId   : Uint read FSCSITargetId;
    property Status         : String read FStatus;
  published
  end;

implementation

uses SysUtils, ActiveX, WbemScripting_TLB;

////////////////////////////////////////////////////////////////////////
////                     TCDROMDrive                               ////
////////////////////////////////////////////////////////////////////////

constructor TCDROMDrive.Create(CDROMDeviceID : String);
begin
  inherited Create;
  FUserName    := UserName;
  FUserPwd     := UserPwd;
  FComputerName := ComputerName;
  SystemValues(CDROMDeviceID);
end;

procedure  TCDROMDrive.SystemValues(CDROMDeviceID : String);
var
  FLocator : ISWbemLocator;
  FServices : ISWbemServices;
  FObjectSet: ISWbemObjectSet;
  FObjEnum : IEnumVariant;
  FWMIObj  : ISWbemObject;
  FWMITmpObj: OleVariant;
  PropVal  : OLEVariant;
  Cnt      : Cardinal;

  function GetValue(Value : String) : Variant;
  begin
    try
       PropVal := (FWMIObj.Properties_.Item(Value, 0) as ISWbemProperty).Get_Value;
       if not (VarIsEmpty(PropVal) or VarIsNull(PropVal)) then Result := PropVal;
    except
    end;
  end;

begin
  FLocator := CoSWbemLocator.Create;
  try
    if FLocator <> nil then
    begin
      FServices := FLocator.ConnectServer('.', 'root\cimv2', '', '', '', '', wbemConnectFlagUseMaxWait, nil);
      if FServices <> nil then
      begin
        FObjectSet := FServices.ExecQuery('SELECT * FROM Win32_CDROMDrive', 'WQL', wbemFlagReturnWhenComplete, nil);
        if FObjectSet <> nil then
        begin
          with FObjectSet do
          begin
            FObjEnum := (FObjectSet._NewEnum) as IEnumVariant;
            if FObjEnum <> nil then
            begin
              if FObjectSet.Count > 0 then
              begin
                while(FObjEnum.Next(1, FWMITmpObj, Cnt) = S_OK) do
                begin
                  FWMIObj := IUnknown(FWMITmpObj) as ISWbemObject;

                  PropVal := (FWMIObj.Properties_.Item('DeviceID', 0) as ISWbemProperty).Get_Value;
                  if not (VarIsEmpty(PropVal) or VarIsNull(PropVal)) and (CDROMDeviceID = PropVal) then
                  begin
                    FDescription     := GetValue('Description');
                    FDrive           := GetValue('Drive');
                    FManufacturer    := GetValue('Manufacturer');
                    FMediaLoaded     := GetValue('MediaLoaded');
                    FMediaType       := GetValue('MediaType');
                    FName            := GetValue('Name');
                    FSCSIBus         := GetValue('SCSIBus');
                    FSCSILogicalUnit := GetValue('SCSILogicalUnit');
                    FSCSIPort        := GetValue('SCSIPort');
                    FSCSITargetId    := GetValue('SCSITargetId');
                    FStatus          := GetValue('Status');
                  end;
                end;
              end;
            end;
          end;
        end;
      end;
    end;
  finally
    FServices := nil;
    FLocator := nil;
  end;
end;

destructor TCDROMDrive.Destroy;
begin
  inherited Destroy;
end;

end.
WMI muss allerdingst installiert bzw. unterstützt werden.
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 13:48 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz