| |

VerySource

 Forgot password?
 Register
Search
Author: cruzer

Super difficult question! How to judge whether it is a U disk according to the drive letter?

[Copy link]

0

Threads

8

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-8-9 18:30:01
| Show all posts
It is definitely possible to use WMI (WMI can get all the system information), the following is a routine (of course, you can judge by Win32_USBControllerDevice or other items):


unit wmi;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
  private
    {Private declarations}
  public
    {Public declarations}
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses
ActiveX, WbemScripting_TLB;
function ADsEnumerateNext(pEnumVariant: IEnumVARIANT; cElements: ULONG;
  var pvar: OleVARIANT; var pcElementsFetched: ULONG): HRESULT; safecall; external'activeds.dll';

procedure DumpWMI_Process(Process: SWBemObject);
var
  Enum: IEnumVARIANT;
  varArr: OleVariant;
  lNumElements: ULong;
  SProp: ISWbemProperty;
  Prop: OleVariant;
  PropName: string;
  PropType: string;
  PropValue: string;
begin
  Form1.Memo1.Lines.Add('+ WMI Path: '+ Process.Path_.Path);
  Enum := Process.Properties_._NewEnum as IEnumVariant;
  while (Succeeded(ADsEnumerateNext(Enum, 1, VarArr, lNumElements))) and
    (lNumElements> 0) do
  begin
    if Succeeded(IDispatch(varArr).QueryInterface(SWBemProperty, SProp)) and
      Assigned(SProp) then
    begin
      try
        PropName := SProp.Name;
        Prop := SProp.Get_Value;
        PropType := inttostr((VarType(Prop)));
        PropValue := VarToStr(Prop);
        Form1.Memo1.Lines.Add(' + '+ PropName +'[' + PropType +'] =' + PropValue);
      except
        on E: Exception do
        begin
          // WriteLn(ErrOutput, PropName,':', E.Message);
        end;
      end;
    end;
  end;
end;



procedure TForm1.Button1Click(Sender: TObject);
var
  Server: string;
  Enum: IEnumVARIANT;
  varArr: OleVariant;
  lNumElements: ULong;
  AName: array[0..255] of Char;
  ASize: DWORD;
begin
  if (ParamCount = 0) then
  begin
    Server :='';
    ASize := SizeOf(AName)-1;
    if GetComputerName(@AName, ASize) then Server := AName;
  end
  else
  begin
    Server := ParamStr(1);
  end;
  try
    Memo1.Lines.BeginUpdate;
    Enum := CoSWbemLocator.Create.ConnectServer(Server,'root\cimv2','',
      '','','', 0, nil).ExecQuery('Select InterfaceType from Win32_DiskDrive','WQL',
      wbemFlagBidirectional, nil)._NewEnum as IEnumVariant;
    while (Succeeded(ADsEnumerateNext(Enum, 1, varArr, lNumElements))) and
      (lNumElements> 0) do
    begin
      DumpWMI_Process(IUnknown(varArr) as SWBemObject);
    end;
  finally
    Memo1.Lines.EndUpdate;
  end;
end;
////WbemScripting_TLB.pas is available from
  ///http://www.truth4all.org/WbemScripting_TLB.pas
  ///Download
   
end.
Reply

Use magic Report

1

Threads

5

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-8-16 14:30:01
| Show all posts
ufoprcYour method is not good !!!
Reply

Use magic Report

1

Threads

5

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-8-16 15:00:01
| Show all posts
ufoprcYour method just returns, the following information cannot be judged that the disk is a USB interface disk!!!


+ WMI Path:\\LITONE-MSJF7C5U\root\cimv2:Win32_DiskDrive.DeviceID="\\\\.\\PHYSICALDRIVE1"
  + DeviceID[8] =\\.\PHYSICALDRIVE1
  + InterfaceType[8] = IDE
+ WMI Path:\\LITONE-MSJF7C5U\root\cimv2:Win32_DiskDrive.DeviceID="\\\\.\\PHYSICALDRIVE0"
  + DeviceID[8] =\\.\PHYSICALDRIVE0
  + InterfaceType[8] = IDE
+ WMI Path:\\LITONE-MSJF7C5U\root\cimv2:Win32_DiskDrive.DeviceID="\\\\.\\PHYSICALDRIVE2"
  + DeviceID[8] =\\.\PHYSICALDRIVE2
  + InterfaceType[8] = USB
Reply

Use magic Report

0

Threads

34

Posts

21.00

Credits

Newbie

Rank: 1

Credits
21.00

 Italy

Post time: 2020-8-16 15:15:01
| Show all posts
InterfaceType[8] = USB
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-8-16 15:45:01
| Show all posts
It certainly works, won't it separate the removable disk from the hard disk?
Reply

Use magic Report

1

Threads

5

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 Vietnam

 Author| Post time: 2020-8-16 19:45:01
| Show all posts
But relying on InterfaceType[8] = USB, it is impossible to determine which drive letter is a USB disk!!!!
Reply

Use magic Report

0

Threads

34

Posts

21.00

Credits

Newbie

Rank: 1

Credits
21.00

 China

Post time: 2020-8-16 20:00:01
| Show all posts
Hehe.... Do you know how the following information is given?

+ WMI Path:\\LITONE-MSJF7C5U\root\cimv2:Win32_DiskDrive.DeviceID="\\\\.\\PHYSICALDRIVE1"
  + DeviceID[8] =\\.\PHYSICALDRIVE1
  + InterfaceType[8] = IDE
+ WMI Path:\\LITONE-MSJF7C5U\root\cimv2:Win32_DiskDrive.DeviceID="\\\\.\\PHYSICALDRIVE0"
  + DeviceID[8] =\\.\PHYSICALDRIVE0
  + InterfaceType[8] = IDE
+ WMI Path:\\LITONE-MSJF7C5U\root\cimv2:Win32_DiskDrive.DeviceID="\\\\.\\PHYSICALDRIVE2"
  + DeviceID[8] =\\.\PHYSICALDRIVE2
  + InterfaceType[8] = USB

Oh, interesting. Who asked you to judge by the above string?
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-18 02:15:02
| Show all posts
It should be possible, study the registry to see
Reply

Use magic Report

0

Threads

12

Posts

12.00

Credits

Newbie

Rank: 1

Credits
12.00

 China

Post time: 2020-8-18 02:30:01
| Show all posts
If the requirements are not high, use the dynamically added fixed disk as a U disk.
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-8-18 17:45:01
| Show all posts
If it is a mobile hard disk connected to USB, I am afraid it will not work.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list