Solved

Rename machine using WMI in VB.Net

Posted on 2008-06-17
3
1,267 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
  • 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

791 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