欢迎光临
我们一直在努力

也许是好东西——Windows Script Host-3[获取硬盘分区信息]

建站超值云服务器,限时71元/月

************************************************
file:    getdrivex.vbs (wsh sample in vbscript)
author:  (c) g. born

showing the properties of a drive by using
filesystemobject
************************************************
option explicit

drive type constants
const unknown = 0
const removable = 1   removable medium
const fixed = 2       fixed medium (hard disk)
const remote = 3      network drive
const cdrom = 4       cd-rom
const ramdisk = 5     ram disk

dim text, title, drive
dim fso, odrive                  object variable

dim drtype(6)
drtype(0) = " unknown "
drtype(1) = " removable "
drtype(2) = " fixed "
drtype(3) = " remote "
drtype(4) = " cdrom "
drtype(5) = " ramdisk "

text = "drive" & vbcrlf & vbcrlf
title = "wsh sample – by g. born"

drive = ""
do                       query drive letter.
    drive = inputbox("drive letter (e.g. a)", "drive", "c")

    if drive = "" then   test for cancel button.
        wscript.quit
    end if

    drive = left(drive, 1)   extract drive letter.
    
     valid drive name (between a and z)?
    if asc(ucase(drive)) < asc("a") or _
       asc(ucase(drive)) > asc("z") then
        msgbox "drive " & drive & " is illegal"
        drive = ""
    end if
loop until drive <> ""

create filesystemobject object to access the file system.
set fso = wscript.createobject("scripting.filesystemobject")

check whether drive exists.
if (not fso.driveexists(drive)) then
    wscript.echo "the drive " & drive & " doesnt exist"
    wscript.quit
end if

set odrive = fso.getdrive(drive)     get drive object.

if (odrive.isready) then
    text = text & ucase(drive) & " – " & odrive.volumename & vbcrlf
    text = text & "drive type: " & drtype(odrive.drivetype) & vbcrlf
    text = text & "file system: " & odrive.filesystem & vbcrlf
    text = text + "capacity: " & _
        formatnumber(odrive.totalsize/(1024*1024), 0) & _
        " mb" & vbcrlf
    text = text & "free: " & formatnumber(odrive.freespace/1024, 0) _
           & " kb" & vbcrlf
else
    text = text & "drive not ready" & vbcrlf
end if

msgbox text, vbokonly + vbinformation, title

*** end

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 也许是好东西——Windows Script Host-3[获取硬盘分区信息]
分享到: 更多 (0)

相关推荐

  • 暂无文章