cagueca Posted April 13, 2009 at 07:26 PM Report #256575 Posted April 13, 2009 at 07:26 PM 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 Try Dim logicalDrive As String For Each logicalDrive In Environment.GetLogicalDrives() ListBox1.Items.Add(logicalDrive) Next logicalDrive Catch ex As Exception MessageBox.Show(ex.Message) End Try End Sub Public Overloads Shared Function Main() As Integer Try 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")) Next 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 " Else 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 ?? Abraço Pus o codigo todo ..
jpaulino Posted April 13, 2009 at 07:51 PM Report #256582 Posted April 13, 2009 at 07:51 PM Mas para listares os nomes dos discos basta isto: Try For Each d As IO.DriveInfo In IO.DriveInfo.GetDrives() Debug.WriteLine(String.Format("Drive: {0}, Nome:{1}", d.Name, d.VolumeLabel)) Next 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 ?
cagueca Posted April 13, 2009 at 08:03 PM Author Report #256584 Posted April 13, 2009 at 08:03 PM Esse debug.writeline posso alterar para messaebox.show ou para label ou listbox certo ??
jpaulino Posted April 13, 2009 at 08:08 PM Report #256587 Posted April 13, 2009 at 08:08 PM Esse debug.writeline posso alterar para messaebox.show ou para label ou listbox certo ?? Sim, claro!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now