Solved

Rename machine using WMI in VB.Net

Posted on 2008-06-17
3
1,273 Views
Last Modified: 2013-11-26
I am looking to call WMI to do a rename and join workgroup.  The following
functions compile cleanly but the renale doesn't seem to work:

Function objGetComputerSystem() As ManagementObject
        Dim objectQuery As New ObjectQuery("select * from
Win32_ComputerSystem")
        Dim searcher As New ManagementObjectSearcher(objectQuery)
        Dim computerSystem As ManagementObject
        Dim computerSystemOut As ManagementObject
        computerSystemOut = Nothing
        For Each computerSystem In searcher.Get()
            computerSystemOut = computerSystem
            Exit For
        Next computerSystem
        Return computerSystemOut
    End Function

    Function renameComputer(ByRef computerSystem As ManagementObject, ByVal
newName As String) As UInt32
        Dim rc As UInt32

        Dim objArgs(1) As Object
        objArgs(0) = newName
        rc = computerSystem.InvokeMethod("Rename", objArgs)
        Return rc

    End Function

    Function JoinWorkgroup(ByRef computerSystem As ManagementObject, ByVal
newWorkgroup As String) As UInt32
        Dim rc As UInt32

        Dim objArgs(5) As Object
        objArgs(0) = newWorkgroup
        objArgs(1) = vbNull
        objArgs(2) = vbNull
        objArgs(3) = vbNull
        objArgs(4) = vbNull


        rc = computerSystem.InvokeMethod("JoinDomainOrWorkgroup", objArgs)
        Return rc

    End Function

The objGetComputerSystem  works but the rename silenlly fails.  I havent
cheched the JoinWorkgroup function yet.  Any Ideas?
0
Comment
Question by:joseph_schuler
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 41

Accepted Solution

by:
graye earned 125 total points
ID: 21813145
just guessing... but I'm wondering if a reboot is required before the rename takes place
0
 
LVL 1

Author Comment

by:joseph_schuler
ID: 21828652
I knew i would have to reboot, but when the machine was part of a domain I also needed to unjoin it first and then join s workgroup, otherwise the rename would not take place.
0
 
LVL 1

Author Closing Comment

by:joseph_schuler
ID: 31468040
see my last comment
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question