0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

cscの作法 その568

Posted at

概要

cscの作法、調べてみた。
練習問題やってみた。

練習問題

USB メモリの情報を取得せよ。

参考にしたページ

サンプルコード

using System;
using System.Management;

namespace DevicesViewer
{
	class Program {
		private static void ShowDevices() {
			var mos = new ManagementObjectSearcher("Select * from Win32_DiskDrive where InterfaceType='USB'");
			foreach (var mo in mos.Get())
			{
				Console.WriteLine(mo);
				foreach (var prop in mo.Properties)
				{
					Console.WriteLine(String.Format("  {0} : {1}", prop.Name, prop.Value));
				}
			}
		}
		static void Main(string[] args) {
			ShowDevices();
		}
	}
}

実行結果

>hid2
\\DESKTOP-6CLR6AB\root\cimv2:Win32_DiskDrive.DeviceID="\\\\.\\PHYSICALDRIVE1"
  Availability :
  BytesPerSector : 512
  Capabilities : System.UInt16[]
  CapabilityDescriptions : System.String[]
  Caption : I-O DATA USB Flash Disk USB Device
  CompressionMethod :
  ConfigManagerErrorCode : 0
  ConfigManagerUserConfig : False
  CreationClassName : Win32_DiskDrive
  DefaultBlockSize :
  Description : ディスク ドライブ
  DeviceID : \\.\PHYSICALDRIVE1
  ErrorCleared :
  ErrorDescription :
  ErrorMethodology :
  FirmwareRevision : 1100
  Index : 1
  InstallDate :
  InterfaceType : USB
  LastErrorCode :
  Manufacturer : (標準ディスク ドライブ)
  MaxBlockSize :
  MaxMediaSize :
  MediaLoaded : True
  MediaType : Removable Media
  MinBlockSize :
  Model : I-O DATA USB Flash Disk USB Device
  Name : \\.\PHYSICALDRIVE1
  NeedsCleaning :
  NumberOfMediaSupported :
  Partitions : 1
  PNPDeviceID : USBSTOR\DISK&VEN_I-O_DATA&PROD_USB_FLASH_DISK&REV_1100\25C21150000600C1&0
  PowerManagementCapabilities :
  PowerManagementSupported :
  SCSIBus : 0
  SCSILogicalUnit : 0
  SCSIPort : 0
  SCSITargetId : 0
  SectorsPerTrack : 63
  SerialNumber : 25C21150000600C1
  Signature : 3272027672
  Size : 7756439040
  Status : OK
  StatusInfo :
  SystemCreationClassName : Win32_ComputerSystem
  SystemName : DESKTOP-6CLR6AB
  TotalCylinders : 943
  TotalHeads : 255
  TotalSectors : 15149295
  TotalTracks : 240465
  TracksPerCylinder : 255
  

以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?