我是靠谱客的博主 甜美口红,这篇文章主要介绍电脑内存硬盘查看器(C++、QT版本和Python、PySide2版本)电脑内存硬盘查看器[序列号和容量](C++、QT版本和Python、PySide2版本)3.C++、QT版本,现在分享给大家,希望可以做个参考。

电脑内存硬盘查看器[序列号和容量](C++、QT版本和Python、PySide2版本)

       由于最近有人问我电脑查看内存卡序列号和硬盘序列号的方式,我告诉他用WMIC指令查看,结果人家告诉我麻烦,于是我就写了这么个小工具,下面附下载链接——免积分。

       首先介绍一下原理,直接用代码调用cmd控制台执行多条指令(wmic)查询信息,然后将信息解析到界面输出。

1.WMIC查询指令

     查询硬盘序列号:

复制代码
1
wmic DiskDrive get serialnumber

    查询硬盘容量:

复制代码
1
wmic DiskDrive get Size /value

    查询内存条序列号:

复制代码
1
wmic Path Win32_PhysicalMemory get serialnumber

    查询内存条容量:

复制代码
1
wmic Path Win32_PhysicalMemory get Capacity /value

2.Python版本

    先是用Python+PySide2写了一个。直接上代码:

CHeckSerialID.py

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#encoding=utf-8 from PySide2.QtCore import QFile from PySide2.QtGui import QIcon from PySide2.QtUiTools import QUiLoader from PySide2.QtWidgets import QWidget class CheckSerialID(QWidget): def __init__(self,parent=None): super().__init__(parent=parent) #加载界面文件QDesigner编写 self.uiFile=QFile("ui/CheckSerialID.ui") self.uiFile.open(QFile.ReadOnly) self.uiLoad=QUiLoader() self.ui=self.uiLoad.load(self.uiFile) #显示界面 self.ui.show(); #设置窗口标题 self.ui.setWindowTitle(u"小黄人硬盘内存查看器") #设计窗口图标 appIcon = QIcon("ui/ico.png") self.ui.setWindowIcon(appIcon) #绑定按钮消息 self.ui.pushButton.clicked.connect(self.getButSlot) ########################################################## #函数名:按钮槽函数 #功 能:响应按钮事件 #参 数:无 ########################################################### def getButSlot(self): mSN= self.getMermoryChipSerialId() dSN= self.getDiskSerialId() memoryVolume=self.getMemoryVolume(); diskVolume=self.getDiskVolme() printS=u"t********一共有"+str(dSN.__len__())+u"个磁盘,"+str(mSN.__len__())+"条内存条********nn" #磁盘信息 i=0; strT="" for snl in dSN: if diskVolume.__len__()<i+1: strT=u"获取磁盘容量失败" else: strT=diskVolume[i] printS=printS+u"t 第"+str(i+1)+u"个磁盘序列号:"+snl+"n" printS=printS+u"t 第"+str(i+1)+u"个磁盘容量为:"+strT+"GBn" i = i + 1 #内存信息 i=0; for snl in mSN: if memoryVolume.__len__()<i+1: strT=u"获取内存大小失败" else: strT=memoryVolume[i] printS = printS + "t第"+str(i+1)+u"条内存条序列号:" + snl + "n"; printS = printS + "t第"+str(i+1)+u"条内存条大小为:" + strT + "GBn"; i=i+1 self.ui.textBrowser.clear() self.ui.textBrowser.setText(printS) return ########################################################## # 函数名:获取内存序列号函数 # 功 能:获取内存序列号 # 输 入:无 # 输 出:返 回 - strList:内存条序列号 ########################################################### def getMermoryChipSerialId(self): import os result =os.popen("wmic memorychip get serialnumber").readlines(); print(result) rlist = [] for ax in result: if ax != 'n' and ax.find("SerialNumber")==-1: ax = ax.replace("Size=", "") ax = ax.replace("n", "") rlist.append(ax) print(rlist) return rlist ########################################################## # 函数名:获取硬盘序列号函数 # 功 能:获取硬盘序列号 # 输 入:无 # 输 出:返 回 - strList:硬盘序列号 ########################################################### def getDiskSerialId(self): from wmi import WMI c = WMI() diskSerialList=[] snl="" # # 硬盘序列号 for physical_disk in c.Win32_DiskDrive(): snl = physical_disk.SerialNumber.replace("n", "") snl = snl.replace(" ", "") diskSerialList.append(snl) return diskSerialList ########################################################## # 函数名:获取内存条容量函数 # 功 能:获取内存条容量 # 输 入:无 # 输 出:返 回 - strList:内存条容量 ########################################################### def getMemoryVolume(self): from os import popen result = popen("wmic Path Win32_PhysicalMemory get Capacity /value").readlines(); rlist = [] from pefile import long for ax in result: if ax != 'n': ax = ax.replace("Capacity=", "") ax = ax.replace("n", "") axi = round(long(ax) / 1024 / 1024 / 1024) rlist.append(str(axi)) return rlist ########################################################## # 函数名:获取硬盘内存函数 # 功 能:获取硬盘内存 # 输 入:无 # 输 出:返 回 - strList:硬盘内存大小GB ########################################################### def getDiskVolme(self): from os import popen from pefile import long result = popen("wmic DiskDrive get Size /value").readlines(); rlist=[] for ax in result: if ax!='n': ax=ax.replace("Size=","") ax=ax.replace("n","") axi=round(long(ax)/1024/1024/1024) rlist.append(str(axi)) return rlist

main.py

复制代码
1
2
3
4
5
6
7
8
9
from sys import exit from PySide2.QtWidgets import QApplication from CheckSerialID import CheckSerialID if __name__=="__main__": app=QApplication([]) w=CheckSerialID() exit(app.exec_())

效果图:

由于Python发行打包后运行贼慢(大约双击后4s才显示界面)于是我准备用C++,QT再写一个。

3.C++、QT版本

直接上代码

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
#include "checkserialnumber.h" /********************************************************** *函数名:构造函数 *功 能:你说呢 *输 入:无 *输 出:无 ***********************************************************/ CheckSerialNumber::CheckSerialNumber(QWidget *parent) : QMainWindow(parent) { ui.setupUi(this); setWindowTitle(QString::fromLocal8Bit("小黄人内存硬盘查看器")); QIcon ico("ico.png"); setWindowIcon(ico); Qt::WindowFlags m_flags = windowFlags(); setWindowFlags(m_flags | Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint); this->setAttribute(Qt::WA_TranslucentBackground);//背景透明 } /********************************************************** *函数名:析构函数 *功 能:你猜 *输 入:无 *输 出:无 ***********************************************************/ CheckSerialNumber::~CheckSerialNumber() { } /********************************************************** *函数名:查询按钮槽函数 *功 能:调用下面查询函数查询并显示到界面 *输 入:无 *输 出:无 ***********************************************************/ void CheckSerialNumber::on_pushButton_clicked() { QStringList MV= getMemoryV(); QStringList MSN = getMemorySN(); QStringList DSN = getDiskSN(); QStringList DV = getDiskV(); QString printS = ""; QString heardS = QString::fromLocal8Bit("t********一共有%1个硬盘和%2条内存条********n").arg(DSN.count()).arg(MSN.count()); printS = printS + heardS; for (int i = 0; i < DSN.count(); i++) { printS = printS + QString::fromLocal8Bit("t 硬盘%1序列号为:%2n").arg(i+1).arg(DSN.at(i)); if (i >= DV.count()) printS = printS + QString::fromLocal8Bit("t 硬盘%1的容量为:获取失败n"); else { printS = printS + QString::fromLocal8Bit("t 硬盘%1的容量为:%2Gn").arg(i+1).arg(DV.at(i)); } } for (int i = 0; i < MSN.count(); i++) { printS = printS + QString::fromLocal8Bit("t内存条%1序列号为:%2n").arg(i+1).arg(MSN.at(i)); if (i >= MV.count()) printS = printS + QString::fromLocal8Bit("t内存条%1的容量为:获取失败n"); else { printS = printS + QString::fromLocal8Bit("t内存条%1的容量为:%2Gn").arg(i+1).arg(MV.at(i)); } } ui.textBrowser->clear(); ui.textBrowser->setText(printS); } /********************************************************** *函数名:查询内存序列号函数 *功 能:查询内存序列号 *输 入:无 *输 出:返回 QStringList:内存序列号列表 ***********************************************************/ QStringList CheckSerialNumber::getMemorySN() { QProcess p(0); p.start("wmic Path Win32_PhysicalMemory get serialnumber"); p.waitForStarted(); p.waitForFinished(); QString result = ""; result = p.readAll(); result = result.remove("SerialNumber"); result = result.remove("r"); result = result.remove(" "); qint64 rv = 0; QStringList listT; QStringList resultList = result.split('n', QString::SkipEmptyParts); for (int i = 0; i < resultList.count(); i++) { if (resultList.at(i) != "") { listT.append(resultList.at(i)); } } return listT; } /********************************************************** *函数名:查询内存容量 *功 能:获取内存容量 *输 入:无 *输 出:返回 QStringList:内存容量列表 ***********************************************************/ QStringList CheckSerialNumber::getMemoryV() { QProcess p(0); p.start("wmic Path Win32_PhysicalMemory get Capacity /value"); p.waitForStarted(); p.waitForFinished(); QString result = ""; result = p.readAll(); result = result.remove("Capacity="); result = result.remove("r"); qint64 rv = 0; QStringList listT; QStringList resultList = result.split('n', QString::SkipEmptyParts); for (int i = 0; i < resultList.count(); i++) { if (resultList.at(i) != "") { rv = resultList.at(i).toLongLong()/1024/1024/1024; listT.append(QString::number(rv)); } } return listT; } /********************************************************** *函数名:获取磁盘序列号函数 *功 能:获取磁盘序列号 *输 入:无 *输 出:返回 QStringList:获取磁盘序列号列表 ***********************************************************/ QStringList CheckSerialNumber::getDiskSN() { QProcess p(0); p.start("wmic DiskDrive get serialnumber"); p.waitForStarted(); p.waitForFinished(); QString result = ""; result = p.readAll(); result = result.remove("SerialNumber"); result = result.remove("r"); result = result.remove(" "); result = result.remove("Size="); qint64 rv = 0; QStringList listT; QStringList resultList = result.split('n', QString::SkipEmptyParts); for (int i = 0; i < resultList.count(); i++) { if (resultList.at(i) != "") { listT.append(resultList.at(i)); } } return listT; } /********************************************************** *函数名:获取磁盘容量函数 *功 能:获取磁盘容量 *输 入:无 *输 出:返回 QStringList:磁盘容量列表 ***********************************************************/ QStringList CheckSerialNumber::getDiskV() { QProcess p(0); p.start("wmic DiskDrive get Size /value"); p.waitForStarted(); p.waitForFinished(); QString result = ""; result = p.readAll(); result = result.remove("Size="); result = result.remove("r"); qint64 rv = 0; QStringList listT; QStringList resultList = result.split('n', QString::SkipEmptyParts); for (int i = 0; i < resultList.count(); i++) { if (resultList.at(i) != "") { rv = resultList.at(i).toLongLong() / 1024 / 1024 / 1024; listT.append(QString::number(rv)); } } return listT; } /********************************************************** *函数名:退出槽函数 *功 能:退出程序 *输 入:无 *输 出:无 ***********************************************************/ void CheckSerialNumber::on_closeBtn_clicked() { this->close(); } /********************************************************** 以下函数是为实现在无窗口边框情况下实现拖拽 ***********************************************************/ void CheckSerialNumber::mousePressEvent(QMouseEvent* e) { if (e->button() == Qt::LeftButton) { this->windowPos = this->pos(); this->mousePos = e->globalPos(); this->dPos = mousePos - windowPos; mBIsWindowMoveable = true; } } void CheckSerialNumber::mouseMoveEvent(QMouseEvent*e) { if (mBIsWindowMoveable) { this->move(e->globalPos() - this->dPos); } } void CheckSerialNumber::mouseReleaseEvent(QMouseEvent* e) { mBIsWindowMoveable = false; }

效果图

 资源下载

  • Python源码下载(码云下载)
  • C++源码下载(码云下载)
  • Python版本应用下载(码云下载 )
  • C++版本应用下载(码云下载)

最后

以上就是甜美口红最近收集整理的关于电脑内存硬盘查看器(C++、QT版本和Python、PySide2版本)电脑内存硬盘查看器[序列号和容量](C++、QT版本和Python、PySide2版本)3.C++、QT版本的全部内容,更多相关电脑内存硬盘查看器(C++、QT版本和Python、PySide2版本)电脑内存硬盘查看器[序列号和容量](C++、QT版本和Python、PySide2版本)3内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(66)

评论列表共有 0 条评论

立即
投稿
返回
顶部