Jump to content

nome do discos rigidos !! Erro

Recommended Posts


Boas :

Mais uma vez um pequeno problemazito ..

E assim tenho este código para ir buscar o nome dos discos rígidos do meu PC ..

Imports System
Imports System.Management
Imports System.Windows.Forms

Namespace WMISample

End Namespace

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Label1.Text = TimeOfDay.ToLongTimeString() 'Hora
        Label3.Text = Environment.ProcessorCount 'Contar processadores
        Label4.Text = Environment.OSVersion.ServicePack ' Versao sistema operativo
        Label5.Text = Environment.UserName.ToString 'Nome User
        Label6.Text = My.Computer.Info.TotalPhysicalMemory.ToString & "  Bites" ' Ram Total supostamente
        Label7.Text = System.DateTime.Today ' Data
        Label8.Text = My.Computer.Info.OSFullName ' Sistema operativo
        Label9.Text = Date.Now.DayOfWeek.ToString ' Dia da semana
        ' Buscar drives do pc
            Dim logicalDrive As String
            For Each logicalDrive In Environment.GetLogicalDrives()
            Next logicalDrive
        Catch ex As Exception
        End Try
    End Sub

    Public Overloads Shared Function Main() As Integer

            Dim searcher As New ManagementObjectSearcher("root\CIMV2", "SELECT * FROM Win32_DiskDrive")

            For Each queryObj As ManagementObject In searcher.Get()

                ListBox2.Items.Add("Caption: {0}", queryObj("Caption"))

        Catch err As ManagementException
            MessageBox.Show("An error occurred while querying for WMI data: " & err.Message)
        End Try
    End Function

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

        Label1.Text = TimeOfDay.ToLongTimeString
        'Ver estado da net Ligado\Desligado
        If My.Computer.Network.IsAvailable = True Then
            Label2.Text = " Conectado "
            Label2.Text = " Nao conectado "
        End If

    End Sub

End Class

mas esta me a dar erro na listbox ... "Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class"

já fui ver ao suporte mas não consigo entender o que esta mal para não dar ...

Podem dar uma ajuda ??


Pus o codigo todo ..

Share this post

Link to post
Share on other sites

Mas para listares os nomes dos discos basta isto:

            For Each d As IO.DriveInfo In IO.DriveInfo.GetDrives()
                  Debug.WriteLine(String.Format("Drive: {0}, Nome:{1}", d.Name, d.VolumeLabel))
        Catch ex As Exception
            ' Ignora em caso de erro
        End Try

Em relação ao teu erro como estás a chamar a função ?

Share this post

Link to post
Share on other sites

Esse debug.writeline posso alterar para messaebox.show ou para label ou listbox certo ??

Sim, claro!

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.