使用C++對(duì)磁盤(pán)進(jìn)行檢測(cè)獲取磁盤(pán)相應(yīng)的信息_第1頁(yè)
免費(fèi)預(yù)覽已結(jié)束,剩余1頁(yè)可下載查看

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、使用c+對(duì)磁盤(pán)進(jìn)行檢測(cè),獲取磁盤(pán)相應(yīng)的信息tern "c" _decpec(dll)int getlogicdiskinfo() int dtype; int si = 0; bool relt; unsign _int64 i64freebytestocaller; unsigned _int64 i64totalbytes; unsigned _int64 i64freebytes; float totalsize;/總空間 float usablesize;/可用空間 int dslength = getlogicaldrivesings(0,null);/通過(guò)該函數(shù)

2、獵取全部驅(qū)動(dòng)器字符串信息長(zhǎng)度 cout "長(zhǎng)度為:" dslength endl; ofstream in;/向文件寫(xiě)內(nèi)容 in.open("d:diskinfo.txt",ios:tru);/ios:trunc表示在打開(kāi)文件前將文件清空,因?yàn)槭菍?xiě)入操作,當(dāng)文件不存在則創(chuàng)建 char* dstr = new chardslength; getlogicaldrivestrings(dslength,(lptstr)dstr); for(int i=0;i dslength/4;+i) char dir3 = dstrsi,':','

3、;' /cout "磁盤(pán)名稱(chēng)為:" dir0 dir1 dir2 endl; in "磁盤(pán)名稱(chēng)為:" dir0 dir1 dir2 "n" char str3 = 0,0,0; str0 = dir0; str1 = dir1; string dirname = str; dtype = getdrivetype(lptstr)dstr+i*4);/通過(guò)該函數(shù)獵取磁盤(pán)的類(lèi)型 string drivertype; if(dtype = drive_fixed) drivertype = "本地磁盤(pán)" /cou

4、t drivertype endl; in "磁盤(pán)類(lèi)型為:" drivertype "n" else if(dtype = drive_cdrom) drivertype = "光驅(qū)" /cout drivertype endl; in "磁盤(pán)類(lèi)型為:" drivertype "n" else if(dtype = drive_removable) drivertype = "可移動(dòng)磁盤(pán)" /cout drivertype endl; in "磁盤(pán)類(lèi)型為:"

5、; drivertype "n" else if(dtype = drive_remote) drivertype = "網(wǎng)絡(luò)磁盤(pán)" /cout drivertype endl; in "磁盤(pán)類(lèi)型為:" drivertype "n" else if(dtype = drive_ramdisk) drivertype = "虛擬ram磁盤(pán)" /cout drivertype endl; in "磁盤(pán)類(lèi)型為:" drivertype "n" else if(d

6、type = drive_unknown) drivertype = "未知設(shè)備" /cout drivertype endl; in "磁盤(pán)類(lèi)型為:" drivertype "n" if(dirname = "c:")/當(dāng)磁盤(pán)為c盤(pán)時(shí) result = getdiskfreespaceex(_t("c:"),(pularge_integer) i64freebytestocaller,(pularge_integer) i64totalbytes,(pularge_integer) i64fr

7、eebytes);/獵取磁盤(pán)的空間狀態(tài) if(result) totalsize = (float)i64totalbytes/1024/1024/1024; usablesize = (float)i64freebytestocaller/1024/1024/1024; /cout "總空間為:" totalsize "gb" endl; /cout "可用空間為:" usablesize "gb" endl; /cout "=" endl; in "總空間為:" tota

8、lsize "gb" "n" in "可用空間為:" usablesize "gb" "n" in "=" "n" else /cout "未檢測(cè)到磁盤(pán)設(shè)備" endl; in "未檢測(cè)到磁盤(pán)設(shè)備" "n" else if(dirname = "d:")/當(dāng)磁盤(pán)為d盤(pán)時(shí) result = getdiskfreespaceex(_t("d:"),(pularg

9、e_integer) i64freebytestocaller,(pularge_integer) i64totalbytes,(pularge_integer) i64freebytes);/獵取磁盤(pán)的空間狀態(tài) if(result) totalsize = (float)i64totalbytes/1024/1024/1024; usablesize = (float)i64freebytestocaller/1024/1024/1024; /cout "總空間為:" totalsize "gb" endl; /cout "可用空間為:&qu

10、ot; usablesize "gb" endl; /cout "=" endl; in "總空間為:" totalsize "gb" "n" in "可用空間為:" usablesize "gb" "n" in "=" "n" else /cout "未檢測(cè)到磁盤(pán)設(shè)備" endl; in "未檢測(cè)到磁盤(pán)設(shè)備" "n" else if(d

11、irname = "e:")/當(dāng)磁盤(pán)為e盤(pán)時(shí) result = getdiskfreespaceex(_t("e:"),(pularge_integer) i64freebytestocaller,(pularge_integer) i64totalbytes,(pularge_integer) i64freebytes);/獵取磁盤(pán)的空間狀態(tài) if(result) totalsize = (float)i64totalbytes/1024/1024/1024; usablesize = (float)i64freebytestocaller/1024/

12、1024/1024; /cout "總空間為:" totalsize "gb" endl; /cout "可用空間為:" usablesize "gb" endl; /cout "=" endl; in "總空間為:" totalsize "gb" "n" in "可用空間為:" usablesize "gb" "n" in "=" "n"

13、; else /cout "未檢測(cè)到磁盤(pán)設(shè)備" endl; in "未檢測(cè)到磁盤(pán)設(shè)備" "n" else if(dirname = "f:")/當(dāng)磁盤(pán)為f盤(pán)時(shí) result = getdiskfreespaceex(_t("f:"),(pularge_integer) i64freebytestocaller,(pularge_integer) i64totalbytes,(pularge_integer) i64freebytes);/獵取磁盤(pán)的空間狀態(tài) if(result) totalsiz

14、e = (float)i64totalbytes/1024/1024/1024; usablesize = (float)i64freebytestocaller/1024/1024/1024; /cout "總空間為:" totalsize "gb" endl; /cout "可用空間為:" usablesize "gb" endl; /cout "=" endl; in "總空間為:" totalsize "gb" "n" in &

15、quot;可用空間為:" usablesize "gb" "n" in "=" "n" else /cout "未檢測(cè)到磁盤(pán)設(shè)備" endl; in "未檢測(cè)到磁盤(pán)設(shè)備" "n" else if(dirname = "g:")/當(dāng)磁盤(pán)為e盤(pán)時(shí) result = getdiskfreespaceex(_t("g:"),(pularge_integer) i64freebytestocaller,(pularg

16、e_integer) i64totalbytes,(pularge_integer) i64freebytes);/獵取磁盤(pán)的空間狀態(tài) if(result) totalsize = (float)i64totalbytes/1024/1024/1024; usablesize = (float)i64freebytestocaller/1024/1024/1024; /cout "總空間為:" totalsize "gb" endl; /cout "可用空間為:" usablesize "gb" endl; /co

17、ut "=" endl; in "總空間為:" totalsize "gb" "n" in "可用空間為:" usablesize "gb" "n" in "=" "n" else /cout "未檢測(cè)到磁盤(pán)設(shè)備" endl; in "未檢測(cè)到磁盤(pán)設(shè)備" "n" si+=8; in.close();/關(guān)閉文件 if(null != dtype) return

18、 dtype; else return -1; 該代碼主要用來(lái)獵取磁盤(pán)的盤(pán)符、磁盤(pán)的類(lèi)型、磁盤(pán)的總空間大小以及磁盤(pán)的可用空間大小。 public ic map string, returnpo getdiscinfo() string dirname = "d:disk" string name = "info.txt" string disknamestr = "磁盤(pán)名稱(chēng)" string disktypestr = "磁盤(pán)類(lèi)型" string totalsizestr = "總空間" stri

19、ng usablesizestr = "可用空間" string diskname = null; string disktype = null; float totalsize = 0; float usablesize = 0; map string, returnpo map = new hashmap string, returnpo returnpo returnpo = new returnpo(); list usbpo list = new arraylist usbpo usbpo usbpo = null; jnative jnative = null;

20、 try jnative = new jnative("pcsuite", "getlogicdiskinfo");/ 加載pcsuite.dll文件 jnative.retval(type.int); / jnative.invoke(); file file = new file(dirname + filename);/ 實(shí)例化文件對(duì)象,讀取一個(gè)放置于本地磁盤(pán)中存放磁盤(pán)信息的文件 if (file.exists() bufferedreader br = new bufferedreader(new filereader(file); string

21、 line = null; int count = 0; int number = 0; for (int i = 0; i = count; i+) while (line = br.readline() != null) if (number % 5 = 0) usbpo = new usbpo();/ 實(shí)例化磁盤(pán)對(duì)象,用來(lái)存放磁盤(pán)信息 if (!"=" .equals(line) if (line.contains(disknamestr) diskname = line .substring(line.indexof(":") + 1);/ 獵取

22、盤(pán)符名稱(chēng) usbpo.setname(diskname);/ 設(shè)置盤(pán)符名稱(chēng) number+; else if (line.contains(disktypestr) disktype = line .substring(line.indexof(":") + 1);/ 獵取磁盤(pán)類(lèi)型 if (disktype.equals(localdiscname)/ 當(dāng)磁盤(pán)類(lèi)型為本地磁盤(pán)時(shí) usbpo.setflag(0);/ 當(dāng)磁盤(pán)類(lèi)型為本地磁盤(pán)時(shí),設(shè)置為0 number+; else if (disktype.equals(movediscname)/ 當(dāng)磁盤(pán)類(lèi)型為可移動(dòng)磁盤(pán)時(shí) us

23、bpo.setflag(1);/ 當(dāng)磁盤(pán)類(lèi)型為可移動(dòng)磁盤(pán)時(shí),設(shè)置為1 number+; else if (line.contains(totalsizestr) totalsize = float.parsefloat(line.substring( line.indexof(":") + 1, line .indexof("gb");/ 獵取磁盤(pán)的總空間 usbpo.settotalsize(totalsize);/ 設(shè)置磁盤(pán)的總空間 number+; else if (line.contains(usablesizestr) usablesize =

24、 float.parsefloat(line.substring( line.indexof(":") + 1, line .indexof("gb");/ 獵取磁盤(pán)的可用空間 usbpo.setusablesize(usablesize);/ 設(shè)置磁盤(pán)的可用空間 number+; if (null != usbpo null != usbpo.getname() !"".equals(usbpo.getname() usbpo.gettotalsize() 0 usbpo.getusablesize() 0) list.a(usbp

25、o);/ 將磁盤(pán)信息添加一個(gè)列表中 else count+; number+; system.out.print("count is:" + count); returnpo.setexcept(null); returnpo.setresultflag(true); returnpo.setresultinfo(list); returnpo.setmethodid(invokemethod.methodid1); map.put(socketserver.resultinfo, returnpo); else logger.error("not ing this file"); ch (nativeexception e) e.printstacktrace(); returnpo.setexcept(e); returnpo.setresultflag(false); r

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論