新客网WWW.XKER.COM:致力做中国最专业的网络学院!
学院: 操作系统 - 网络应用 - 服务器 - 网络安全 - 工具软件 - 办公软件 - Web开发 - 数据库 - 网页设计 - 图形图像 - 媒体动画 - 硬件学堂 - 存储频道 - QQ专区
您的位置:首页 > 软件开发 > Web开发 > Asp教程 > 正文:也许是好东西——Windows Script Host-3[获取硬盘分区信息]

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

新客网 XKER.COM 2003-07-11 来源: 收藏本文
'************************************************
' 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 & " doesn't 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
收藏】 【评论】 【推荐】 【投稿】 【打印】 【关闭
发表评论
要记得去论坛讨论,点击注册新会员匿名评论
评论内容:不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
阅读排行
随机推荐
实用信息推荐