
下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、使用c+對磁盤進行檢測,獲取磁盤相應(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);/通過該函數(shù)
2、獵取全部驅(qū)動器字符串信息長度 cout "長度為:" dslength endl; ofstream in;/向文件寫內(nèi)容 in.open("d:diskinfo.txt",ios:tru);/ios:trunc表示在打開文件前將文件清空,因為是寫入操作,當(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 "磁盤名稱為:" dir0 dir1 dir2 endl; in "磁盤名稱為:" dir0 dir1 dir2 "n" char str3 = 0,0,0; str0 = dir0; str1 = dir1; string dirname = str; dtype = getdrivetype(lptstr)dstr+i*4);/通過該函數(shù)獵取磁盤的類型 string drivertype; if(dtype = drive_fixed) drivertype = "本地磁盤" /cou
4、t drivertype endl; in "磁盤類型為:" drivertype "n" else if(dtype = drive_cdrom) drivertype = "光驅(qū)" /cout drivertype endl; in "磁盤類型為:" drivertype "n" else if(dtype = drive_removable) drivertype = "可移動磁盤" /cout drivertype endl; in "磁盤類型為:"
5、; drivertype "n" else if(dtype = drive_remote) drivertype = "網(wǎng)絡(luò)磁盤" /cout drivertype endl; in "磁盤類型為:" drivertype "n" else if(dtype = drive_ramdisk) drivertype = "虛擬ram磁盤" /cout drivertype endl; in "磁盤類型為:" drivertype "n" else if(d
6、type = drive_unknown) drivertype = "未知設(shè)備" /cout drivertype endl; in "磁盤類型為:" drivertype "n" if(dirname = "c:")/當(dāng)磁盤為c盤時 result = getdiskfreespaceex(_t("c:"),(pularge_integer) i64freebytestocaller,(pularge_integer) i64totalbytes,(pularge_integer) i64fr
7、eebytes);/獵取磁盤的空間狀態(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 "未檢測到磁盤設(shè)備" endl; in "未檢測到磁盤設(shè)備" "n" else if(dirname = "d:")/當(dāng)磁盤為d盤時 result = getdiskfreespaceex(_t("d:"),(pularg
9、e_integer) i64freebytestocaller,(pularge_integer) i64totalbytes,(pularge_integer) i64freebytes);/獵取磁盤的空間狀態(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 "未檢測到磁盤設(shè)備" endl; in "未檢測到磁盤設(shè)備" "n" else if(d
11、irname = "e:")/當(dāng)磁盤為e盤時 result = getdiskfreespaceex(_t("e:"),(pularge_integer) i64freebytestocaller,(pularge_integer) i64totalbytes,(pularge_integer) i64freebytes);/獵取磁盤的空間狀態(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 "未檢測到磁盤設(shè)備" endl; in "未檢測到磁盤設(shè)備" "n" else if(dirname = "f:")/當(dāng)磁盤為f盤時 result = getdiskfreespaceex(_t("f:"),(pularge_integer) i64freebytestocaller,(pularge_integer) i64totalbytes,(pularge_integer) i64freebytes);/獵取磁盤的空間狀態(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 "未檢測到磁盤設(shè)備" endl; in "未檢測到磁盤設(shè)備" "n" else if(dirname = "g:")/當(dāng)磁盤為e盤時 result = getdiskfreespaceex(_t("g:"),(pularge_integer) i64freebytestocaller,(pularg
16、e_integer) i64totalbytes,(pularge_integer) i64freebytes);/獵取磁盤的空間狀態(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 "未檢測到磁盤設(shè)備" endl; in "未檢測到磁盤設(shè)備" "n" si+=8; in.close();/關(guān)閉文件 if(null != dtype) return
18、 dtype; else return -1; 該代碼主要用來獵取磁盤的盤符、磁盤的類型、磁盤的總空間大小以及磁盤的可用空間大小。 public ic map string, returnpo getdiscinfo() string dirname = "d:disk" string name = "info.txt" string disknamestr = "磁盤名稱" string disktypestr = "磁盤類型" 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);/ 實例化文件對象,讀取一個放置于本地磁盤中存放磁盤信息的文件 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();/ 實例化磁盤對象,用來存放磁盤信息 if (!"=" .equals(line) if (line.contains(disknamestr) diskname = line .substring(line.indexof(":") + 1);/ 獵取
22、盤符名稱 usbpo.setname(diskname);/ 設(shè)置盤符名稱 number+; else if (line.contains(disktypestr) disktype = line .substring(line.indexof(":") + 1);/ 獵取磁盤類型 if (disktype.equals(localdiscname)/ 當(dāng)磁盤類型為本地磁盤時 usbpo.setflag(0);/ 當(dāng)磁盤類型為本地磁盤時,設(shè)置為0 number+; else if (disktype.equals(movediscname)/ 當(dāng)磁盤類型為可移動磁盤時 us
23、bpo.setflag(1);/ 當(dāng)磁盤類型為可移動磁盤時,設(shè)置為1 number+; else if (line.contains(totalsizestr) totalsize = float.parsefloat(line.substring( line.indexof(":") + 1, line .indexof("gb");/ 獵取磁盤的總空間 usbpo.settotalsize(totalsize);/ 設(shè)置磁盤的總空間 number+; else if (line.contains(usablesizestr) usablesize =
24、 float.parsefloat(line.substring( line.indexof(":") + 1, line .indexof("gb");/ 獵取磁盤的可用空間 usbpo.setusablesize(usablesize);/ 設(shè)置磁盤的可用空間 number+; if (null != usbpo null != usbpo.getname() !"".equals(usbpo.getname() usbpo.gettotalsize() 0 usbpo.getusablesize() 0) list.a(usbp
25、o);/ 將磁盤信息添加一個列表中 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. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 【正版授權(quán)】 IEC 60068-2-1:2007 EN-D Environmental testing - Part 2-1: Tests - Test A: Cold
- 農(nóng)村人才引進與培養(yǎng)合作框架協(xié)議
- 高中物理實驗技能強化課
- 合作開發(fā)技術(shù)合同協(xié)議書要求
- 農(nóng)村用地規(guī)劃利用與管理協(xié)議
- 法律職業(yè)資格考試大綱卷樣題集
- 銀行歷史考試試題及答案
- 儀器qc考試試題及答案
- 六一兒童公開課活動方案
- 六一公司食堂活動方案
- 【上料機械手結(jié)構(gòu)中的真空系統(tǒng)的設(shè)計計算案例1100字】
- 西方美術(shù)史試題及答案
- 七年級數(shù)學(xué)下學(xué)期期末測試卷(1)(學(xué)生版+解析)-2025年七年級數(shù)學(xué)下學(xué)期期末總復(fù)習(xí)(北師大版)
- 校園短劇創(chuàng)作與演出指導(dǎo)行業(yè)跨境出海項目商業(yè)計劃書
- 2025年北京豐臺區(qū)九年級中考二模英語試卷試題(含答案詳解)
- 【7歷期末】安徽省合肥市包河區(qū)2023-2024學(xué)年部編版七年級下學(xué)期期末歷史試卷
- 新生兒收治流程規(guī)范與實施
- T/CBMCA 017-2021建筑用覆膜鋼板
- 《重癥監(jiān)護病房的臨終關(guān)懷和姑息治療指南》解讀
- 2025年初中地理會考試卷
- 中國鈦基復(fù)合材料行業(yè)市場前景預(yù)測及投資價值評估分析報告
評論
0/150
提交評論