时间: 2021-07-31 作者:daque
大概你并不领会硬盘分区消息该当囊括些什么,但即使你已经对硬盘分过区,你大概对此有所领会,在此为诸位引见一个用vb编写的获得硬盘分区消息的步调。在这个步调中,它将精细地报告你:你的硬盘总含量、分过几个区、每个区的总含量、及此刻结余的可用含量、硬盘分区表为几位(即是fat32仍旧fat16),每个分区是几个字节……如何样?够完备精细了吧!好的,就让咱们一道来看一下吧: 开始做筹备处事:在form1上兴建二个label(label1和label2)一个command1吩咐按钮。而后输出以次代码: private declare function getdrivetype lib kernel32“alias "getdrivetypea(byval ndrive as string) as long private declare function getdiskfreespace lib“kernel32" alias“getdiskfreespacea" (byval lprootpathname as string, lpsectorspercluster as long, lpbytespersector as long, lpnumberoffreeclusters as long, lpttoalnumberofclusters as long) as long private const drive_fixed = 3 private sub form_load() ‘作初始化树立 command1.caption = “尝试硬盘" form1.caption = “尝试硬盘步调" label1.wordwrap = true label1.caption = “" label2.wordwrap = true label2.caption = “" end sub private sub command1_click() dim drivenum as integer dim tempdrive as string dim x as long for drivenum = 97 to 122 step 1 ‘检验和测定从a-z(盘符) tempdrive = getdrivetype(chr(drivenum) & “:\") select case tempdrive ‘如是3则表白是硬盘,尝试你有几个盘 case 3: x = getdiskspace(chr(drivenum)) ‘挪用子步调 end select next drivenum end sub public function getdiskspace(drivepath as string) dim drive as string dim sectorspercluster as long dim bytespersector as long dim numberoffreeclusters as long dim totalclusters as long dim check as integer dim diskspace dim disktotal static alldisktotal as long static num as integer num = num + 1 ‘分几个区的计划 drive = left(trim(drivepath), 1) & “:\" check = getdiskfreespace(drive, sectorspercluster, bytespersector, numberoffreeclusters, totalclusters) if check <> 0 then diskspace = sectorspercluster * bytespersector * numberoffreeclusters ‘这是一个分区磁盘结余空间的计划公式 diskspace = format$(diskspace, “###,###") ‘以规则方法表露,如732,324,231 disktotal = sectorspercluster * bytespersector * totalclusters ‘这是一个分区磁盘总含量的计划公式 disktotal = format$(disktotal, “###,###") alldisktotal = alldisktotal + disktotal ‘所有硬盘的总含量 label1.caption =“你的硬盘总含量为:” & format$(alldisktotal,“###,###") &个字节,即:” & left(alldisktotal, 1) & . & mid(alldisktotal, 2, 1) &“g,所有分了”& num &“个区,个中:" label2.caption = label2.caption & ucase(drivepath) & “盘的所有含量为:" & disktotal &“个字节" & ",其结余磁盘空间为:“& diskspace & " 个字节,磁盘已fat“& sectorspercluster & ",每个分区为:“& bytespersector & "个字节。“& vbcrlf & vbcrlf” end if end function ok!此刻你运转一下,你能否合意它? 注:之上步调在华文windows98,华文vb6.0企业版中调节和测试经过。