joseph_schuler
asked on
Rename machine using WMI in VB.Net
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(o bjectQuery )
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.InvokeMetho d("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.InvokeMetho d("JoinDom ainOrWorkg roup", objArgs)
Return rc
End Function
The objGetComputerSystem works but the rename silenlly fails. I havent
cheched the JoinWorkgroup function yet. Any Ideas?
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(o
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.InvokeMetho
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.InvokeMetho
Return rc
End Function
The objGetComputerSystem works but the rename silenlly fails. I havent
cheched the JoinWorkgroup function yet. Any Ideas?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
see my last comment
ASKER