Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 2 - Listing/Modifying Server Information with ...
Moblin
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Actuate Whitepapers 
Moblin 
JMSL Numerical Library 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
VISUAL BASIC.NET

Listing/Modifying Server Information with Visual Basic.NET and VBScript Using WMI
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 5
    2005-12-13

    Table of Contents:
  • Listing/Modifying Server Information with Visual Basic.NET and VBScript Using WMI
  • Listing minimum server information using WMI
  • How to retrieve all user account information using WMI
  • How to retrieve all group information along with account information using WMI
  • How to change your computer name using WMI

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    Listing/Modifying Server Information with Visual Basic.NET and VBScript Using WMI - Listing minimum server information using WMI


    (Page 2 of 5 )

    How can you find out information about your server?  By this I mean its name, domain, workgroup, and so on. The following VB.NET code should supply some minimum information on your server.

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Try
                Dim searcher As New ManagementObjectSearcher( _
                    "root\CIMV2", _
                    "SELECT * FROM Win32_ComputerSystem")
                Dim en As ManagementObjectEnumerator = searcher.Get.GetEnumerator
                If en.MoveNext Then
                    Dim queryObj As ManagementObject = en.Current
                    Dim dt As DataTable = globals.getStructure()
                    globals.addRow(dt, "Caption", queryObj
    ("Caption"))
                    globals.addRow(dt, "Name", queryObj("Name"))
                    globals.addRow(dt, "UserName", queryObj
    ("UserName"))
                    globals.addRow(dt, "DNSHostName", queryObj
    ("DNSHostName"))
                    globals.addRow(dt, "Description", queryObj
    ("Description"))
                    globals.addRow(dt, "PartOfDomain", queryObj
    ("PartOfDomain"))
                    globals.addRow(dt, "Domain", queryObj("Domain"))
                    globals.addRow(dt, "Workgroup", queryObj
    ("Workgroup"))
                    dt.AcceptChanges()
                    Me.DataGrid1.DataSource = dt
                End If
     
            Catch err As ManagementException
                MessageBox.Show("An error occurred while querying for WMI data: " & err.Message)
            End Try
        End Sub

    I excluded some of the properties (as it would make the program too long) from the existing WMI class (Win32_ComputerSystem) to give you only the most important ones.  The above program would list the server name, user logged in, DNSHostName, description (if any), whether it's part of a domain or not, the domain it belongs to, and finally the workgroup it belongs to.  You can further extend the above program with several other properties available in the “Win32_ComputerSystem” class.  You can even refer to MSDN online for further properties.

    You can achieve the same thing with VBScript by using the following code:

    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
    Set colItems = objWMIService.ExecQuery( _
        "SELECT * FROM Win32_ComputerSystem",,48)
    For Each objItem in colItems
          Wscript.Echo "Caption: " & objItem.Caption
          Wscript.Echo "Name: " & objItem.Name
        Wscript.Echo "UserName: " & objItem.UserName
        Wscript.Echo "DNSHostName: " & objItem.DNSHostName
        Wscript.Echo "Description: " & objItem.Description
        Wscript.Echo "PartOfDomain: " & objItem.PartOfDomain
        Wscript.Echo "Domain: " & objItem.Domain
        Wscript.Echo "Workgroup: " & objItem.Workgroup
    Next

    More Visual Basic.NET Articles
    More By Jagadish Chaterjee


       · I hope you enjoyed this article on how to retrieve information from your server....
     

    VISUAL BASIC.NET ARTICLES

    - Entity Creation and Messaging in a VB.NET Te...
    - Movement and Player Statistics in a VB.NET T...
    - Creating and Drawing a Game Map in VB.NET
    - Working with Classes and Properties for Game...
    - Working with Loops, Arrays, and Collections ...
    - Learning Loops in VB.NET for Game Development
    - Learning VB.NET: Working with Variables, Con...
    - The Basics of VB.NET Through Text Game Devel...
    - Learning VB.NET Through Text Game Development
    - Types of Operators in Visual Basic
    - Operators
    - Understanding Custom Events using Visual Bas...
    - Polymorphism using Abstract Classes in Visua...
    - Shadowing using Shadows in Visual Basic.NET ...
    - Overloading and Overriding in Visual Basic.N...




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway