Solved

Rename machine using WMI in VB.Net

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now