码迷,mamicode.com
首页 > 其他好文 > 详细

autoit使用WMIC获取硬件信息

时间:2015-07-10 18:42:20      阅读:477      评论:0      收藏:0      [点我收藏+]

标签:

效果图:

技术分享

直接上源码了

#cs ----------------------------------------------------------------------------

AutoIt Version: 3.3.12.0
Author: Qiulp

Script Function:
Template AutoIt script.

#ce ----------------------------------------------------------------------------
#include <file.au3>
#include <array.au3>

#include <GUIConstantsEx.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <ListviewConstants.au3>

Local $fp_PCInfo = @ScriptDir & "\PCInfo.txt"
Local $strPCInfoFormat = "csv"

If FileExists($fp_PCInfo) Then
FileDelete($fp_PCInfo)
EndIf

Local $strNicConfig = "wmic nicconfig list brief /format:" & $strPCInfoFormat & " >>" & $fp_PCInfo
Local $strOS = "wmic OS list brief /format:" & $strPCInfoFormat & " >>" & $fp_PCInfo
Local $strBOIS = "wmic bios list brief /format:" & $strPCInfoFormat & " >>" & $fp_PCInfo
Local $strMemorychip = "wmic memorychip get manufacturer, PartNumber,SerialNumber,Capacity,DeviceLocator,MemoryType,Name,TotalWidth /format:" & $strPCInfoFormat & " >>" & $fp_PCInfo
Local $strCPU = "wmic CPU list brief /format:" & $strPCInfoFormat & " >>" & $fp_PCInfo
Local $strDiskdrive = "wmic diskdrive list brief /format:" & $strPCInfoFormat & " >>" & $fp_PCInfo
Local $strSoundDev = "wmic SoundDev list brief /format:" & $strPCInfoFormat & " >>" & $fp_PCInfo
Local $strBaseboard = "wmic baseboard list brief /format:" & $strPCInfoFormat & " >>" & $fp_PCInfo

Local $aPCAlias[8][2]
$aPCAlias[0][0] = "OS"
$aPCAlias[0][1] = $strOS
$aPCAlias[1][0] = "BIOS"
$aPCAlias[1][1] = $strBOIS
$aPCAlias[2][0] = "Baseboard"
$aPCAlias[2][1] = $strBaseboard
$aPCAlias[3][0] = "CPU"
$aPCAlias[3][1] = $strCPU
$aPCAlias[4][0] = "Memory"
$aPCAlias[4][1] = $strMemorychip
$aPCAlias[5][0] = "Diskdrive"
$aPCAlias[5][1] = $strDiskdrive
$aPCAlias[6][0] = "Sound"
$aPCAlias[6][1] = $strSoundDev
$aPCAlias[7][0] = "Net"
$aPCAlias[7][1] = $strNicConfig

_WritePCInfo()
Local $aArray = FileReadToArray($fp_PCInfo)
Local $iRowIndex = 1

If UBound($aArray) <= 8 Then
MsgBox(0, "", "Can not collect PC information.")
Exit
EndIf

#Region ### START Koda GUI section ### Form=
$formPC = GUICreate("PC information collection tool", 1000, 437, 192, 124)
$tabType = GUICtrlCreateTab(10, 10, 982, 420)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT+$GUI_DOCKRIGHT+$GUI_DOCKTOP+$GUI_DOCKBOTTOM+$GUI_DOCKHCENTER+$GUI_DOCKVCENTER+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)

Local $lvHandle[UBound($aPCAlias)]
Local $strCurrentString, $aTemp
For $i = 0 To UBound($aPCAlias) - 1
GUICtrlCreateTabItem($aPCAlias[$i][0])

$strCurrentString = $aArray[$iRowIndex]
$lvHandle[$i] = GUICtrlCreateListView(StringReplace($strCurrentString, ",", "|"), 16, 35, 970, 390, bitor($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
GUISetBkColor(0x00E0FFFF)
$iRowIndex += 1

While $aArray[$iRowIndex] <> ""
$strCurrentString = $aArray[$iRowIndex]
If $aPCAlias[$i][0] == "Memory" Then
$aTemp = StringSplit($strCurrentString, ",", 2)
$aTemp[1] = _SwitchToMb($aTemp[1])
$strCurrentString = _ArrayToString($aTemp, ",")
EndIf

If $aPCAlias[$i][0] == "Diskdrive" Then
$aTemp = StringSplit($strCurrentString, ",", 2)
$aTemp[5] = _SwitchToMb($aTemp[5])
$strCurrentString = _ArrayToString($aTemp, ",")
EndIf

GUICtrlCreateListViewItem(StringReplace($strCurrentString, ",", "|"), $lvHandle[$i])
$iRowIndex += 1
If $iRowIndex = UBound($aArray) Then ExitLoop
WEnd

$iRowIndex += 1 ;jump the empty row
Next

GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit

EndSwitch
WEnd

Func _SwitchToMb($strNumber)
Return String(int(Number($strNumber) / (1024 * 1024))) & " Mb"
EndFunc

Func _WritePCInfo()
For $i = 0 To UBound($aPCAlias) - 1
;ConsoleWrite($aPCAlias[$i][1] & @CRLF)
RunWait(@ComSpec & " /c " & $aPCAlias[$i][1], @ScriptDir, @SW_HIDE)
_AppendLineToFile($fp_PCInfo, @CRLF)
Next
EndFunc

Func _AppendLineToFile($strFilepath, $strContent)
Local $hFileOpen = FileOpen($strFilepath, $FO_APPEND)
If $hFileOpen = -1 Then
MsgBox(0, "", "An error occurred when reading the file.")
Return False
EndIf

; Write data to the file using the handle returned by FileOpen.
FileWriteLine($hFileOpen, $strContent)

; Close the handle returned by FileOpen.
FileClose($hFileOpen)
EndFunc

autoit使用WMIC获取硬件信息

标签:

原文地址:http://www.cnblogs.com/jenney-qiu/p/4636345.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!