我正在製作一個程序來提升電腦性能,其中一項功能是碎片整理。但如果這個腳本運行一個SSD它不會對它有好處。因此,任何人都知道如何檢測他們是否使用SSD或HDD,以便我可以編程以在需要時跳過此步驟。我想也許是速度測試,但我不知道這是否可靠。有誰知道我該如何做到這一點。謝謝批量檢查某人是否正在使用HDD或SSD
1
A
回答
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
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();
相關問題
- 1. 從HDD獲取RPM,如果磁盤是SSD或不在vb.net
- 2. 如何檢查某人是否正在引用該dll?
- 3. 批量檢查文件是否存在
- 4. 如何檢查某人是否正在運行我的程序?
- 5. 檢查某個月某人是否住在某家旅館,SQL
- 6. 如何使用批量檢查文件是否存在
- 7. 如何檢查某個進程是否正在運行或不
- 8. 檢查是否$ _POST變量是人口
- 9. linux上的文件訪問ssd + hdd
- 10. 使用批處理或JavaScript來檢查文件是否打開
- 11. 檢查PHP SessionID是否正在使用?
- 12. 檢查文件是否正在使用
- 13. 如何檢查某人是否是用戶?
- 14. 如何確定某人是否正在Python或Java中使用Linux計算機?
- 15. Btrfs可以將SSD用於元數據並將批量數據保留在HDD上嗎?
- 16. 常見的HDD和SSD是否可以保證整個扇區被寫入?
- 17. 檢查是否存在,是否存在,是否爲某個值
- 18. 我應該使用SSD還是HDD作爲kubernetes集羣的本地磁盤?
- 19. 如何檢查變量是否含有用java在機器人
- 20. 是否可以在Linq 2 Sql中批量或批量插入?
- 21. 如何檢查文本文件是否批量包含某些文本?
- 22. 如何檢查批次中是否按下了某個鍵?
- 23. 檢查在運行時是否正在執行某個方法
- 24. 批量檢查一個變量是否爲
- 25. 檢查文件是否存在批量文件中的數組
- 26. 如何檢查批量傳遞參數是否存在?
- 27. 檢查是否仍在使用Windows批處理腳本
- 28. 檢查是否存在目錄使用批處理文件
- 29. 檢查驅動器是否真的是一個USB使用批量
- 30. 如何檢查日期是否在某個星期或季度
我建議在SuperUser上問這個問題。 –