BAT 显示磁盘详细信息

BAT 显示磁盘详细信息

1.简介:

windows bash脚本,保存文本重命名后缀为xxx.bat,双击运行即可

' 2>nul 3>nul&cls&@echo off
'&title Disk partition capacity information
'&cscript -nologo -e:vbscript "%~f0"
'&pause&exit
 
On Error Resume Next
Set fso=CreateObject("Scripting.Filesystemobject")
Set ws=CreateObject("WScript.Shell")
Set wmi=GetObject("winmgmts:\\.\root\cimv2")
Set query1=wmi.ExecQuery("Select * from Win32_DiskDrive")
For Each item1 in query1
    WSH.echo "Caption=" & item1.Caption
    WSH.echo "DeviceID=" & item1.DeviceID
    WSH.echo "InterfaceType=" & item1.InterfaceType
    WSH.echo "MediaType=" & item1.MediaType
    WSH.echo "Size=" & SizeFormat(item1.Size) 
    WSH.echo "=================================================================================================================="
    index=item1.Index
    If index <> "" Then
        Set query2=wmi.ExecQuery("Select * from Win32_LogicalDiskToPartition")
        For Each item2 in query2
            If InStr(item2.Antecedent, "Disk #" & index & ",") >0 Then
                drive=replace(split(item2.Dependent,"=")(1), """", "")
                If drive <> "" Then
                    Set query3=wmi.ExecQuery("Select * from Win32_LogicalDisk where Caption='" & drive & "'")
                    For Each item3 in query3
                        line=""
                        line=line & item3.Caption & " | "
                        line=line & item3.Description & " | "
                        line=line & item3.FileSystem & " | "
                        line=line &"Total:"& SizeFormat(item3.Size) & " | "
                        line=line & " Available:"& SizeFormat(item3.FreeSpace) & " | "
                        line=line &"Used capacity:"& SizeFormat(item3.Size - item3.FreeSpace) & " | "
                        line=line & "Usage rate:"& FormatNumber((item3.Size - item3.FreeSpace) / item3.Size, 2, true) * 100 & "%"
                        rem echo Disk letter |  Disk type   | Partition format  | Total capacity  |   Available capacity  |   Used capacity   |  Capacity usage
                        WSH.echo line
                    Next
                End If
            End If
        Next
    End If
    WSH.echo ""
Next
 
Function SizeFormat(size)
    If size >= 1099511627776 Then
        SizeFormat = FormatNumber(size/1099511627776, 2, true) & " TB"
    ElseIf size >= 1073741824 Then
        SizeFormat = FormatNumber(size/1073741824, 2, true) & " GB"
    ElseIf size >= 1048576 Then
        SizeFormat = FormatNumber(size/1048576, 2, true) & " MB"
    ElseIf size >= 1024 Then
        SizeFormat = FormatNumber(size/1024, 2, true) & " KB"
    Else
        SizeFormat = size & "B"    
    End If
End Function

2.运行效果

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

创客白泽

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值