Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 5 - Listing/Modifying Server Information with ...
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  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
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 / 8
    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


    Listing/Modifying Server Information with Visual Basic.NET and VBScript Using WMI - How to change your computer name using WMI


    (Page 5 of 5 )

    You can change your computer name using VB.NET and WMI as shown in the following:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
    As System.EventArgs) Handles Button1.Click
            Try
                Dim classInstance As New ManagementObject( _
                    "root\CIMV2", _
                    "Win32_ComputerSystem.Name='SERVER'", _
                    Nothing)
                Dim inParams As ManagementBaseObject = _
                    classInstance.GetMethodParameters("Rename")
                inParams("Name") = "server2" 'rename to
                inParams("Password") = "admin"
                inParams("UserName") = "administrator"
                Dim outParams As ManagementBaseObject = _
                    classInstance.InvokeMethod("Rename", inParams,
    Nothing)
                MessageBox.Show("ReturnValue: {0}", outParams
    ("ReturnValue"))
            Catch err As ManagementException
                MessageBox.Show("Error: " & err.Message)
            End Try
        End Sub

    Note that I am using “InvokeMethod” to execute a WMI method (in this case “Rename”) dynamically.  “inParams” (an object of ManagementBaseObject) is specifically used to pass parameters to the WMI method “Rename”.  It mainly contains the required information to penetrate through the authentication and authorization (username and password) of security, along with the new computer name.  We can get the result after executing the WMI method “Rename” into “outParams”.

    You can achieve the same result using the following VBScript code:

    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
    Set objShare = objWMIService.Get("Win32_ComputerSystem.Name='SERVER'")
    Set objInParam = objShare.Methods_("Rename").inParameters.SpawnInstance_()
    objInParam.Properties_.Item("Name") =  "server2"
    objInParam.Properties_.Item("Password") =  "admin"
    objInParam.Properties_.Item("UserName") =  "administrator"
    Set objOutParams = objWMIService.ExecMethod("Win32_ComputerSystem.Name='SERVER'", "Rename", objInParam)
    Wscript.echo "ReturnValue: " & objOutParams.ReturnValue

    Summary

    You can further delve into the classes of WMI and design your own application to manage almost every important aspect of the Windows OS.  If you extend your skills to ASP.NET, then you can develop a web application which can manage your server information on the fly, without your presence in the office itself!  I think you can imagine the same, if you further extend it to the Pocket PC level!  Good luck.

    Anyway, once again, I must be thankful to all the readers who appreciated and encouraged me to further expand the series in a much more useful and efficient manner.  Thank you very much.

    Any comments, suggestions, bugs, errors, feedback etc. are highly appreciated at jag_chat@yahoo.com.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

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

    VISUAL BASIC.NET ARTICLES

    - User-defined Functions using Visual Basic Ap...
    - Understanding Object Binding in VBA
    - Mastering the Message Box
    - Testing a Windows Forms Application
    - Using Visual Basic.NET Features to Code a Wi...
    - Correcting Code in a Windows Forms Applicati...
    - Write Readable Code and Comments for Windows...
    - How to Code and Test a Windows Forms Applica...
    - Adding Features to a Windows Forms Applicati...
    - How to Design a Windows Forms Application
    - LINQ to XML Programming Using Visual Basic.N...
    - Understanding Delegates using Visual Basic.N...
    - Create a Sudoku Puzzle Generator using VB.NET
    - Entity Creation and Messaging in a VB.NET Te...
    - Movement and Player Statistics in a VB.NET T...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek