waldgnarf
Goto Top

S.M.A.R.T. HDD Temperatur in vb.Net

Hallo, ich bin dabei ein Programm zu basteln was mir die Temperatur meiner Festplatte ausliest.
Es funktioniert auch alles sehr gut nur weiss ich nicht wie man eine Funktion refreshen kann.
Ich benutze ein Timer aber der refresht die ausgelesenen Daten nicht.

Imports System.Runtime.InteropServices

Public Class Form1
    Dim NUMMER As Integer


    Public Enum ReadSmart_Results
        DRIVE_DOES_NOT_EXIST
        ACCESS_DENIED
        NO_SMART_AVAILABLE
        SUCCEEDED
    End Enum
    Public Enum Attributes
        SMART_ATTRIB_Invalid = 0
        SMART_ATTRIB_AIRFLOW_TEMPERATURE = 190
        SMART_ATTRIB_HDA_TEMPERATURE = 194
    End Enum
    Private Const IOCTL_STORAGE_PREDICT_FAILURE As Integer = &H2D1100
    Private Const STATUS_INVALID_DEVICE_REQUEST As Integer = &HC0000010
    Private Const FILE_SHARE_NONE As Short = 0
    Private Const OPEN_EXISTING As Short = 3
    Private Const INVALID_HANDLE_VALUE As Short = -1
    Private Const GENERIC_READ As Integer = &H80000000
    Private Const GENERIC_WRITE As Integer = &H40000000
    Private Const FILE_SHARE_READ As Integer = 1
    Private Const FILE_SHARE_WRITE As Integer = 2
    Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Integer, ByVal dwShareMode As Integer, ByVal lpSecurityAttributes As IntPtr, ByVal dwCreationDisposition As Integer, ByVal dwFlagsAndAttributes As Integer, ByVal hTemplateFile As IntPtr) As IntPtr  
    Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As IntPtr) As Boolean  
    Private Declare Function DeviceIoControl Lib "kernel32" (ByVal hDevice As IntPtr, ByVal dwIoControlCode As Integer, ByRef lpInBuffer As IntPtr, ByVal nInBufferSize As Integer, <Out()> ByVal lpOutBuffer As STORAGE_PREDICT_FAILURE, ByVal nOutBufferSize As Integer, ByRef lpBytesReturned As Integer, ByVal lpOverlapped As IntPtr) As Integer  
    Public DRIVES, BEZEIC As String()
    Dim STRLA1, STRLA2, STRLH1, STRLH2 As String
    Dim INTOFF, INTATT, INTVAL, INTWOR, INTDAT As Integer
    Dim INTLAU As Integer = 0
    Dim LISVIE As ArrayList
    Public SmartData As STORAGE_PREDICT_FAILURE
    Public Function GetPhysicalDrives()
        Dim COLITE As Object
        Dim A As Integer
        COLITE = GetObject("winmgmts:\\.\root\cimv2").ExecQuery("SELECT * FROM Win32_DiskDrive")  
        DRIVES = New String(COLITE.count - 1) {}
        BEZEIC = New String(COLITE.count - 1) {}
        A = 0
        For Each OBJITE In COLITE
            DRIVES(A) = OBJITE.deviceid()
            BEZEIC(A) = OBJITE.caption
            If A = 0 Then LATEH1.Text = BEZEIC(A)
            If A = 1 Then LATEH2.Text = BEZEIC(A)
            A += 1
        Next
        Return COLITE.Count
    End Function
    Public Function ReadSmart(ByVal STRLAU As String) As ReadSmart_Results
        Dim DEVICE As IntPtr
        Dim RESULT As Boolean
        Dim RETBYT As Integer
        SmartData = New STORAGE_PREDICT_FAILURE
        DEVICE = CreateFile(STRLAU, GENERIC_READ, FILE_SHARE_READ, IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero)
        If DEVICE.ToInt32 = INVALID_HANDLE_VALUE Then
            If Marshal.GetLastWin32Error = 5 Then
                Return ReadSmart_Results.ACCESS_DENIED
            Else
                Return ReadSmart_Results.DRIVE_DOES_NOT_EXIST
            End If
        End If
        RESULT = DeviceIoControl(DEVICE, IOCTL_STORAGE_PREDICT_FAILURE, IntPtr.Zero, 0, SmartData, Marshal.SizeOf(SmartData), RETBYT, IntPtr.Zero)
        CloseHandle(DEVICE)
        If RESULT Then
            Return ReadSmart_Results.SUCCEEDED
        Else
            Return ReadSmart_Results.NO_SMART_AVAILABLE
        End If
    End Function

    Public Sub GetSmartValue(ByVal INTOFF As Integer, ByRef INTATT As Integer, ByRef INTVAL As Integer, ByRef INTWOR As Integer, ByRef INTDAT As Integer)
        If SmartData.VendorSpecific(INTOFF) = 190 Or SmartData.VendorSpecific(INTOFF) = 194 Then
            Dim STRINT As String = ""  
            For Z As Integer = 11 To 5 Step -1
                STRINT &= Hex(SmartData.VendorSpecific(INTOFF + Z))
            Next
            INTDAT = Convert.ToInt64(STRINT, 16)
            INTLAU += 1
            If SmartData.VendorSpecific(INTOFF) = 190 Then
                If INTLAU < 3 Then
                    STRLA1 = "AIR" & " / " & INTDAT & " / " & NUMMER  
                Else
                    STRLA2 = "AIR" & " / " & INTDAT  
                End If
            Else
                If INTLAU < 3 Then
                    STRLH1 = "HDA" & " / " & INTDAT  
                Else
                    STRLH2 = "HDA" & " / " & INTDAT  
                End If
            End If
        End If
    End Sub
    Public Sub SMAARR(ByVal LISVIE As ArrayList, ByVal INTIND As Integer)
        For A As Integer = 0 To 29
            GetSmartValue(A * 12 + 2, INTATT, INTVAL, INTWOR, INTDAT)
        Next
    End Sub


    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim B As Integer = GetPhysicalDrives() - 1
        For C As Integer = 0 To B
            ReadSmart(DRIVES(C))
            SMAARR(LISVIE, C)
        Next

        LABLA1.Text = STRLA1
        LABLA2.Text = STRLA2
        LABLH1.Text = STRLH1
        LABLH2.Text = STRLH2
    End Sub
End Class

<StructLayout(LayoutKind.Sequential)> Public Class STORAGE_PREDICT_FAILURE
    Public PredictFailure As Integer
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=512)> Public VendorSpecific() As Byte
    Sub New()
        VendorSpecific = New Byte(511) {}
    End Sub
End Class

Grüße waldgnarf

Content-ID: 159017

Url: https://administrator.de/forum/s-m-a-r-t-hdd-temperatur-in-vb-net-159017.html

Ausgedruckt am: 23.12.2024 um 13:12 Uhr

76109
76109 19.01.2011 um 22:39:58 Uhr
Goto Top
Hallo waldgnarf!

Keine Ahnung von vb-net, aber finde ich in Deinem Code keinen Hinweis auf das setzen des <Timer1.Interval = 0815> und den <Timer1.Start()>?

Gruß Dieter
waldgnarf
waldgnarf 20.01.2011 um 09:23:05 Uhr
Goto Top
Oh welch peinlicher Fehler.

        Timer1.Enabled = True
        Timer1.Interval = 100

Im Timer1 geschrieben und es Funktioniert.

THX

Grüße waldgnarf