Jump to content
startuga

[Resolvido] Explicação de Código

Recommended Posts

startuga

Têm como alguem me explicar este codigo?

Imports System.Management

Public Class phoenix_informacaosistema1

   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       Dim Searcher As ManagementObjectSearcher
       Dim Device As ManagementObject
       Dim Computer As TreeNode
       Dim DeviceName As TreeNode
       Dim i As Integer
       Dim w As Integer

       trvDevices.BeginUpdate()
       lsvProperties.BeginUpdate()
       Try
           Me.Cursor = Cursors.WaitCursor

           GroupBox1.Enabled = False
           GroupBox2.Enabled = False

           trvDevices.Nodes.Clear()

           Searcher = New ManagementObjectSearcher("Select * from Win32_ComputerSystem")
           For Each device In Searcher.get
               Computer = trvDevices.Nodes.Add(device.item("caption").ToString)
           Next

           pBar.Value = 0
           pBar.Maximum = DevicesArr.Length
           pBar.Visible = False

           For i = 0 To DevicesArr.Length - 1
               pBar.Value += 1
               Try
                   DeviceName =
                       Computer.Nodes.Add(DevicesArr(i).Replace("Win32_", ""))
                   Searcher = New ManagementObjectSearcher("Select * from " & DevicesArr(i))
                   For Each Device In Searcher.get
                       DeviceName.Nodes.Add(Device.item("Caption").ToString)
                   Next
               Catch ex As Exception
               Finally
               End Try
           Next
           pBar.Visible = False
       Catch ex As Exception
       Finally
           Computer.Expand()
           GroupBox1.Enabled = True
           GroupBox2.Enabled = True
           trvDevices.EndUpdate()
           lsvProperties.EndUpdate()
           Me.Cursor = Cursors.Default

       End Try

   End Sub

   Private Sub trvDevices_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles trvDevices.AfterSelect
       Dim Searcher As ManagementObjectSearcher
       'Dim Device As ManagementObject
       Dim Path() As String

       lsvProperties.BeginUpdate()

       Path = e.Node.FullPath.Split("\")
       If Path.Length = 3 Then
           lsvProperties.Items.Clear()
           Searcher = New ManagementObjectSearcher("Select * From Win32_" & Path(1))
           For Each Device As ManagementObject In Searcher.Get
               If Device.Item("Caption").ToString = Path(2) Then
                   Dim Itm As ListViewItem
                   For Each Prop As PropertyData In Device.Properties
                       'lsvProperties.Items.Add(Prop.Name.ToString).SubItems.Add(Prop.Value.ToString)
                       Itm = lsvProperties.Items.Add(Prop.Name.ToString)
                       If Not IsNothing(Prop.Value) Then
                           Itm.SubItems.Add(Prop.Value.ToString)
                       Else
                           Itm.SubItems.Add("")
                       End If
                   Next
               End If
           Next
       End If
       lsvProperties.EndUpdate()

   End Sub

   Private Sub frmMain_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
       lsvProperties.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize)
   End Sub

   Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       Dim W As Integer

       W = lsvProperties.Width / 2
       lsvProperties.Columns.Add("Property", W)
       lsvProperties.Columns.Add("Value", W)
       lsvProperties.View = View.Details
       lsvProperties.GridLines = True

       Button1_Click(sender, e)


   End Sub

Edited by pmg
GeSHi

Share this post


Link to post
Share on other sites
ruiribeiro

À primeira vista parece ser um form com uma treeview e uma listview

Na treeview estão a ser carregados os dispositvos presentes na máquina

Ao seleccionares um desses dispositivos, aparece na listview uma lista de Propriedades/valor

Basicamente, isto trata-se de uma implementação de utilização de WMI (Windows Management Instrumentation) em vb.net, para obter Informações de sistema.

Edited by ruiribeiro

Rui Ribeiro

.NET/T-SQL, JAVA, PHP, Javascript Developer

Share this post


Link to post
Share on other sites
startuga

À primeira vista parece ser um form com uma treeview e uma listview

Na treeview estão a ser carregados os dispositvos presentes na máquina

Ao seleccionares um desses dispositivos, aparece na listview uma lista de Propriedades/valor

Basicamente, isto trata-se de uma implementação de utilização de WMI (Windows Management Instrumentation) em vb.net, para obter Informações de sistema.

Obrigado, já agora outra coisa se me poder ajudar,

- Pelo que consegui intender minimamente do código está a ser utilizado um ciclo "for" ou mais que um, o que fazem exactamente esses ciclos ?

Share this post


Link to post
Share on other sites
ruiribeiro

	    Searcher = New ManagementObjectSearcher("Select * from Win32_ComputerSystem")
	    For Each device In Searcher.get
		    Computer = trvDevices.Nodes.Add(device.item("caption").ToString)
	    Next

vê bem este loop... o que achas que ele faz ?

Edited by ruiribeiro

Rui Ribeiro

.NET/T-SQL, JAVA, PHP, Javascript Developer

Share this post


Link to post
Share on other sites
startuga

Searcher = New ManagementObjectSearcher("Select * from Win32_ComputerSystem")
For Each device In Searcher.get
Computer = trvDevices.Nodes.Add(device.item("caption").ToString)
Next

vê bem este loop... o que achas que ele faz ?

Pelo aquilo que eu consegui entender

O programa vai fazer uma pesquisa através do "Win32_ComputerSystem".

Depois cada dispositivo que for encontrado será colocado dentro da "trv, treeview". Contudo continuo sem entender o que faz o próximo ciclo "for".

Next

           pBar.Value = 0
           pBar.Maximum = DevicesArr.Length
           pBar.Visible = False

           For i = 0 To DevicesArr.Length - 1
               pBar.Value += 1
               Try
                   DeviceName =
                       Computer.Nodes.Add(DevicesArr(i).Replace("Win32_", ""))
                   Searcher = New ManagementObjectSearcher("Select * from " & DevicesArr(i))
                   For Each Device In Searcher.get
                       DeviceName.Nodes.Add(Device.item("Caption").ToString)
                   Next
               Catch ex As Exception
               Finally
               End Try
           Next
           pBar.Visible = False
       Catch ex As Exception

       Finally

Se me puderem ajudar agradecia;

Edited by thoga31
Tags code + GeSHi

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.

Guest
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.