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?
"PzkwVIb" wrote: > 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? You need to restart the computer in order to see the changed name. Have you tried that? -- urkec
Yes, I have tried rebooting. No joy. "urkec" wrote: > "PzkwVIb" wrote: > > > 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? > > > You need to restart the computer in order to see the changed name. Have you > tried that? > > -- > urkec
I just found out if I remove teh computer from the domain first the rename works. Thanks "urkec" wrote: > "PzkwVIb" wrote: > > > 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? > > > You need to restart the computer in order to see the changed name. Have you > tried that? > > -- > urkec