2014-06-05 126 views
1

我正在製作一個程序來提升電腦性能,其中一項功能是碎片整理。但如果這個腳本運行一個SSD它不會對它有好處。因此,任何人都知道如何檢測他們是否使用SSD或HDD,以便我可以編程以在需要時跳過此步驟。我想也許是速度測試,但我不知道這是否可靠。有誰知道我該如何做到這一點。謝謝批量檢查某人是否正在使用HDD或SSD

+0

我建議在SuperUser上問這個問題。 –

回答

1

這些信息可以從wmic命令中獲得;例如:

C:\> wmic logicaldisk get Description,DeviceID 
Description   DeviceID 
Local Fixed Disk C: 
Local Fixed Disk D: 
CD-ROM Disk   E: 
Removable Disk  G: 

下面使用批處理文件中的此方法,以確定是HDD中的驅動器:

@echo off 

for /F "tokens=1-4" %%a in ('wmic logicaldisk get Description^,DeviceID') do (
    if "%%a %%b %%c" equ "Local Fixed Disk" (
     echo Drive %%d is a HDD 
    ) 
) 

例如:

C:\> test.bat 
Drive C: is a HDD 
Drive D: is a HDD 

EDIT兩個新的驅動器添加識別方法

似乎以前的方法在所有情況下都不可靠。下面有兩個更精確的新方法:一個肯定的方法,檢查給定的驅動器是否是基於LogicalDisk/DriveType = 3的HDD,否定的方法是檢查給定的驅動器是否是而不是 HDD是基於分區上的IDE盤具有(盤驅動/ InterfaceType = IDE):

@echo off 

echo Drive type identification using LogicalDisk/DriveType=3: 
for /F "tokens=1-2" %%a in ('wmic LogicalDisk get DeviceID^,DriveType') do (
    if "%%b" equ "3" (
     echo Drive %%a is a HDD 
    ) 
) 

echo/ 
echo Drive type identification using DiskDrive/InterfaceType=IDE: 
set partitions=0 
for /F "tokens=1-2" %%a in ('wmic DiskDrive get InterfaceType^,Partitions') do (
    if "%%a" equ "IDE" set /A partitions+=%%b 
) 
set drives=BCDEFGHIJKLMNOPQRSTUVWXYZ 
call set lastIDEdrive=%%drives:~%partitions%,1%%: 
echo Last IDE interface logical drive (B:=none): %lastIDEdrive% 
for /F %%a in ('wmic LogicalDisk get DeviceID') do (
    if "%%a" gtr "%lastIDEdrive%" (
     echo Drive %%a is NOT a HDD 
    ) 
) 

例如:

C:\> test.bat 
Drive type identification using LogicalDisk/DriveType=3: 
Drive C: is a HDD 
Drive D: is a HDD 

Drive type identification using DiskDrive/InterfaceType=IDE: 
Last IDE interface logical drive (B:=none): F: 
Drive G: is NOT a HDD 
+1

這是否說明了HDD和SSD之間的區別?我認爲從我完成的閱讀中可以確切地說明這一點。 – foxidrive

+0

@foxidrive:根據我的理解,如果磁盤是HDD_,操作系統只想做一些事情,所以沒有必要確定磁盤是否是SSD(或CD-ROM等)。當然,只有OP可以清除這一點,但即使在這種情況下,我認爲wmic報告「可移動磁盤」時唯一的情況就是SSD。 – Aacini

+0

OP希望整理除SSD型號之外的驅動器。所以他需要確定驅動器號是否是SSD。 – foxidrive

4

簡答:沒有可靠的方法。

龍答:

問題「Is there any way of detecting if a drive is a SSD」提出了一些啓發,但他們都不似乎是可靠的。

此問題也被問到on Lockergnome,但在我的系統上,我無法通過運行MSInfo32從硬盤告訴我的SSD。

On CNet答案是查找驅動器模型和谷歌它。這可能不是您想要從批處理文件中執行的操作。

post on the OCZ forum建議找一個0的旋轉。但作爲Flimm commented,它有時躺着。

A Wordpress blog post建議使用隨機讀取傳輸速率,但這也是啓發式的。 RAID系統可能會逃避這種檢測。

- 關於@Aacini的答案

更新,證明這是行不通:

腳本報告:

D:\>test-hdd.bat 
Drive type identification using LogicalDisk/DriveType=3: 
Drive C: is a HDD 
Drive D: is a HDD 
Drive E: is a HDD 
Drive F: is a HDD 

Drive type identification using DiskDrive/InterfaceType=IDE: 
Last IDE interface logical drive (B:=none): F: 
Drive G: is NOT a HDD 

真實情況:

Drive C: is a SSD (logical partition 1 of SSD 1) 
Drive D: is a SSD (logical partition 2 of SSD 1) 
Drive E: is a SSD (only partition of SSD 2) 
Drive F: is a HDD 
Drive G: is NOT a HDD (it's a USB stick) 
2

了smartmontools是一個強大的命令行工具,可以在批量使用

http://sourceforge.net/projects/smartmontools/?source=directory

c:\>smartctl -i sda 
smartctl 6.4 2015-06-04 r4109 [x86_64-w64-mingw32-win7-sp1] (sf-6.4-1) 
Copyright (C) 2002-15, Bruce Allen, Christian Franke, www.smartmontools.org 

=== START OF INFORMATION SECTION === 
Model Family:  HGST Travelstar 5K1000 


User Capacity: 1,000,204,886,016 bytes [1.00 TB] 
Sector Sizes:  512 bytes logical, 4096 bytes physical 
Rotation Rate: 5400 rpm 
Form Factor:  2.5 inches 
Device is:  In smartctl database [for details use: -P show] 
ATA Version is: ATA8-ACS T13/1699-D revision 6 
SATA Version is: SATA 2.6, 6.0 Gb/s (current: 3.0 Gb/s) 
Local Time is: Thu Oct 22 20:27:40 2015 
SMART support is: Available - device has SMART capability. 
SMART support is: Enabled 

c:\>smartctl -i sdb 
smartctl 6.4 2015-06-04 r4109 [x86_64-w64-mingw32-win7-sp1] (sf-6.4-1) 
Copyright (C) 2002-15, Bruce Allen, Christian Franke, www.smartmontools.org 

=== START OF INFORMATION SECTION === 

Sector Size:  512 bytes logical/physical 
Rotation Rate: Solid State Device 
Device is:  In smartctl database [for details use: -P show] 

SATA Version is: SATA 3.0, 6.0 Gb/s (current: 6.0 Gb/s) 
Local Time is: Thu Oct 22 20:28:01 2015 
SMART support is: Available - device has SMART capability. 
SMART support is: Enabled 

→_→SSD:

c:\>smartctl -a c: 
smartctl 6.4 2015-06-04 r4109 [i686-w64-mingw32-win7(64)-sp1] (sf-6.4-1) 
Copyright (C) 2002-15, Bruce Allen, Christian Franke, www.smartmontools.org 

=== START OF INFORMATION SECTION === 
Model Family:  SandForce Driven SSDs 
Device Model:  KINGSTON SV300S37A120G 

User Capacity: 120,034,123,776 bytes [120 GB] 
Sector Size:  512 bytes logical/physical 
Rotation Rate: Solid State Device 
2

我寫了下面的JavaScript代碼。我需要知道我是否有SSD驅動器,以及它是否是啓動驅動器。

function main() 
{ 
    var retval= false; 
    // MediaType - 0 Unknown, 3 HDD, 4 SSD 
    // SpindleSpeed - -1 has rotational speed, 0 has no rotational speed (SSD) 
    // DeviceID - 0 boot device 
    var objWMIService = GetObject("winmgmts:\\\\.\\root\\Microsoft\\Windows\\Storage"); 
    var colItems = objWMIService.ExecQuery("select * from MSFT_PhysicalDisk"); 
    var enumItems = new Enumerator(colItems); 
    for (; !enumItems.atEnd(); enumItems.moveNext()) 
    { 
     var objItem = enumItems.item(); 
     if (objItem.MediaType == 4 && objItem.SpindleSpeed == 0) 
     { 
      if (objItem.DeviceID == 0) 
      { 
       retval=true; 
      } 
     } 
    } 
    if (retval) 
    { 
     WScript.Echo("You have SSD Drive and it is your boot drive."); 
    } 
    else 
    { 
     WScript.Echo("You do not have SSD Drive"); 
    } 
    return retval; 
} 

main(); 
相關問題