Rubrik: System/Windows · Sonstiges | VB-Versionen: VB6 | 13.05.04 |
CPU Temperatur, Systemspannungen uvm. auslesen Bei diesem Tipp handelt es sich um eine Erkennung der CPU- und Mainboardtemperatur, sowie allen relevanten Spannungen im System. | ||
Autor: David Müller | Bewertung: | Views: 46.532 |
www.funprogz.de | System: Win9x, WinNT, Win2k, WinXP, Win7, Win8, Win10, Win11 | Beispielprojekt auf CD |
Zu einem vollkommenen Systeminformationsprogramm gehören meiner Ansicht nach auch die aktuellen Temperaturen im System. Aber auch zum Anlegen einer Statistik eignet sich folgender Code: Auf der Basis des Freeware-Tools Motherboard-Monitor können Sie mit Visual Basic alle wichtigen Systemspannungen und Temperaturen sowie Lüfterdrehzahlen ermitteln. Natürlich ist es nicht als eigenständiges Programm zu gebrauchen, da im Hintergrund immer "Motherboard Monitor" aktiv sein muss. Aber als Statistik-Programm zur eigenen Information ist es mangels einer entsprechenden Funktion in MBM selbst allemal geeignet. Die aktuellste Version von MBM bekommen Sie hier:
http://mbm.livewiredev.com
Nachfolgender Code ist eine modifizierte Version von modMBMAccess519.zip, der bei mir in der "Urform" nicht funktionierte.
Erstellen Sie zunächst ein Standard-EXE-Projekt und fügen der Form einen Commandbutton (Command1) und eine Textbox (Text1) mit der Eigenschaft "Multiline = True" hinzu.
Option Explicit ' Erst einmal die benötigten API's Private Declare Sub CopyMemoryRead Lib "kernel32" _ Alias "RtlMoveMemory" ( _ Destination As Any, _ ByVal Source As Long, _ ByVal Length As Long) Private Declare Sub CopyMemoryWrite Lib "kernel32" _ Alias "RtlMoveMemory" ( _ ByVal Destination As Long, _ Source As Any, _ ByVal Length As Long) Private Declare Function OpenFileMapping Lib "kernel32" _ Alias "OpenFileMappingA" ( _ ByVal dwDesiredAccess As Long, _ ByVal bInheritHandle As Long, _ ByVal lpName As String) As Long Private Declare Function CloseHandle Lib "kernel32" ( _ ByVal hObject As Long) As Long Private Declare Function MapViewOfFile Lib "kernel32" ( _ ByVal hFileMappingObject As Long, _ ByVal dwDesiredAccess As Long, _ ByVal dwFileOffsetHigh As Long, _ ByVal dwFileOffsetLow As Long, _ ByVal dwNumberOfBytesToMap As Long) As Long Private Declare Function UnmapViewOfFile Lib "kernel32" ( _ ByVal lpBaseAddress As Long) As Long ' Es folgen alle für den Zugriff benötigten ' Deklarationen Private Const FILE_MAP_WRITE = &H2 Private Const FILE_MAP_READ = &H4 Private Const MBMnumSensors = 99 Private Const MBMnumVoltages = 10 Private Const MBMnumFans = 10 Private Const MBMnumCPUs = 4 Private Enum MBMBusType btISA = 0 btSMBus = 1 btVIA686ABus = 2 btDirectIO = 3 End Enum Private Enum MBMSMBType smtSMBIntel = 0 smtSMBAMD = 1 smtSMBALi = 2 smtSMBNForce = 3 smtSMBSIS = 4 End Enum Private Enum MBMSensorType stUnknown = 0 stTemperature = 1 stVoltage = 2 stFan = 3 stMhz = 4 stPercentage = 5 End Enum Private Type MBMSharedSensor ssType As Byte ssName As String * 12 ssPad1 As String * 3 ssCurrent As Double ssLow As Double ssHigh As Double ssCount As Long ssPad2 As String * 4 ssTotal As Double ssPad3 As String * 6 ssAlarm1 As Double ssAlarm2 As Double End Type Private Type MBMSharedIndex iType As MBMSensorType Count As Integer End Type Private Type MBMSharedInfo siSMB_Base As Integer siSMB_Type As Byte siSMB_Code As Byte siSMB_Addr As Byte siSMB_Name As String * 41 siISA_Base As Integer siChipType As Long siVoltageSubType As Byte End Type Private Type MBMSharedData sdVersion As Double sdIndex(0 To 9) As MBMSharedIndex sdSensor(0 To 99) As MBMSharedSensor sdInfo As MBMSharedInfo sdStart As String * 41 sdCurrent As String * 41 sdPath As String * 256 End Type Dim n
Private Function XTrim(sStr As String) As String Dim oStr As String Dim pos As Integer Dim l As Integer oStr = RTrim(LTrim(sStr)) l = Len(oStr) If l > 0 Then For pos = l To 0 Step -1 If Mid(oStr, l, 1) = Chr(0) Then oStr = Left(oStr, l - 1) l = l - 1 Else Exit For End If If l = 0 Then Exit For Next pos End If XTrim = oStr End Function
Private Function MBM_GetSharedData( _ Optional bSilent As Boolean = True) As MBMSharedData Static myDataStruct As MBMSharedData Dim myMBMFile As Long Dim myMBMMem As Long myMBMFile = OpenFileMapping(FILE_MAP_READ, _ False, "$M$B$M$5$S$D$") If myMBMFile = 0 Then If (bSilent) Then Exit Function Else MsgBox "MBM Data File/Mem could not be opened. Sorry." Exit Function End If End If myMBMMem = MapViewOfFile(myMBMFile, FILE_MAP_READ, 0, 0, 0) CopyMemoryRead myDataStruct, myMBMMem, Len(myDataStruct) UnmapViewOfFile myMBMMem CloseHandle myMBMFile MBM_GetSharedData = myDataStruct End Function
Private Function MBM_SetSensorValue(SensorID As Integer, _ Value As Integer) As Integer Static myDataStruct As MBMSharedData Dim myMBMFile As Long Dim myMBMMem As Long myMBMFile = OpenFileMapping(FILE_MAP_WRITE, False, "$M$B$M$5$S$D$") If myMBMFile = 0 Then MBM_SetSensorValue = 0 Exit Function End If myMBMMem = MapViewOfFile(myMBMFile, FILE_MAP_WRITE, 0, 0, 0) CopyMemoryRead myDataStruct, myMBMMem, Len(myDataStruct) myDataStruct.sdSensor(SensorID).ssCurrent = Value CopyMemoryWrite myMBMMem, myDataStruct, Len(myDataStruct) UnmapViewOfFile myMBMMem CloseHandle myMBMFile MBM_SetSensorValue = Value End Function
Private Sub infos() ' Sub zum Schreiben der Daten ' in das Textfeld Dim myData As MBMSharedData myData = MBM_GetSharedData Text1.Text = "" & vbCrLf & vbCrLf For n = 0 To MBMnumSensors If n = 16 Then Text1.Text = Text1.Text + vbCrLf If n = 50 Then Text1.Text = Text1.Text + vbCrLf If myData.sdSensor(n).ssCurrent <> "255" Then If myData.sdSensor(n).ssCurrent <> "0" Then Text1.Text = Text1.Text + " Sensor" & n & _ " (" & XTrim(myData.sdSensor(n).ssName) & ") : " & _ myData.sdSensor(n).ssCurrent & vbCrLf End If End If If Text1.Text = vbCrLf & vbCrLf Then Text1.Text = "MBM5 nicht installiert, falsch " & _ "konfiguriert oder nicht aktiv." End If Next n End Sub
Private Sub Command1_Click() ' Refreshen ' bei Bedarf auch in einen Timer "verpackbar" Call infos End Sub
Private Sub Form_Load() ' Daten einlesen und Textfeld sperren Call infos Text1.Locked = True End Sub