重命名远程计算机并将其从域中删除 [英] Rename a Remote Computer and remove it from the domain

查看:87
本文介绍了重命名远程计算机并将其从域中删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的任务是创建一个半自动化的GUI,以从域中删除计算机,然后对其进行重命名(以为硬件换出方案释放现有名称)

现在,我一直沿用创建脚本的想法,该脚本使用NETDOM从域中删除计算机,该域将在重新启动后通过注册表中的一次运行选项运行,但是宁愿有一个更干净的选项供VB从使用管理员用户凭据的GUI界面.将计算机从域中删除后,在工作组中(任何名称),都可以将计算机重命名为正确的名称,然后重新加入域.

这听起来可能有点冗长,但是在域上使用临时名称构建计算机,并且当需要硬件换出时,将从域中删除临时计算机名称,将计算机重命名为要换出的计算机的名称,然后重新加入域.

简而言之,我需要从域中删除远程计算机并将其重命名.

我希望我有道理....

Hi,

I have a task to create an semi automated GUI to remove a computer from the domain and then rename it (to free up the existing name for a hardware swap-out scenario)

Now I have though along the idea of creating scripts that use NETDOM to remove the machine from the domain that will be run via the run once option in the registry after a reboot, but would rather have a cleaner option for VB to do it from the GUI interface using the admin users credentials. Once the Computer is removed from the domain and in a workgroup (of any name) then the computer can be renamed to the correct name and then rejoined to the Domain.

This might sound a bit long winded but machines are built with temporary names on the domain and when a hardware swap-out is required the temp computer name is removed from the domain, the computer renamed to the name of the computer being swapped out and then rejoined to the domain.

In a nutshell, I need to remove a remote computer from a domain and rename it.

I hope I''m making sense....

推荐答案

是否通过编程方式 [ ^ ]帮助?
我通过谷歌搜索以编程方式重命名远程计算机"找到了这些.上面的结果在第一页上.
Does this[^] or this[^] help?
I found these by googling "programmatically rename a remote computer". The results above were on the first page.


谢谢,但这两个解决方案都是C#,我一直在寻找VB解决方案.

我通过Google进行了拖网捕捞,发现了一些但不是全部的想法...我将研究C#解决方案,看看是否可以使它们适应VB,但C#不是我的语言...

再次感谢.
Thanks for that, but both these solutions are C# I was looking for a VB solution.

I have trawled though google and found ideas that do some but not all... I will look at the C# solutions and see if I can adapt them to VB, but C# is not my language...

Thanks again.


如果有人需要,我已经设法在这里对我的代码进行了排序.只要访问权限正确,此方法就可以在远程计算机上使用.

I have managed to sort this here''s my code if anyone needs it. This works on remote machines as long as the access rights are correct.

Imports System
Imports Microsoft.Win32
Imports System.Management
Imports System.Management.Instrumentation

        Try 'Remove from Domain

            Dim ComputerName as string = "" 'Insert Computer Name Here
            Dim ConnectionOpt As New ConnectionOptions()
            ConnectionOpt.Authentication = AuthenticationLevel.PacketPrivacy
            Console.WriteLine("Connecting to " & ComputerName & " WMI Namespace")

            Dim scope As New ManagementScope("\\" & ComputerName & _
            "\root\cimv2", ConnectionOpt)
            scope.Connect()
            Console.WriteLine("Connection Succeeded")
            Dim classInstance As New ManagementObject(scope, _
            New ManagementPath("Win32_ComputerSystem.Name='" _
            & ComputerName & "'"), Nothing)
            Dim inParams As ManagementBaseObject = _
            classInstance.GetMethodParameters("unjoindomainorworkgroup")
            Console.WriteLine("Removing " & ComputerName  & _
            " from Domain and adding to Workgroup")
            inParams("FunjoinOptions") = 1
            inParams("Password") = "xxxxxxxx" ' Password Here
            inParams("UserName") = "xxxxxxxx" ' Local Admin User

            Dim outParams As UInt32 = _
            classInstance.InvokeMethod("unjoindomainorworkgroup", Nothing)
            Console.WriteLine("Removal Succeeded.")
        Catch err As ManagementException
            Console.WriteLine("Removal Failed!")
            Console.WriteLine("Error: " & err.Message)
        End Try

        Try 'Changes Computer Name
            Console.WriteLine("Connecting to " & ComputerName & " WMI Namespace")
            Dim ConnectionOpt As New ConnectionOptions()
            ConnectionOpt.Authentication = AuthenticationLevel.PacketPrivacy

            Dim scope As New ManagementScope("\\" & ComputerName & _
            "\root\cimv2", ConnectionOpt)
            scope.Connect()
            Console.WriteLine("Connection Succeeded")
            Console.WriteLine("Renaming " & ComputerName & " to " _
            & NewComputerName ")
            Dim classInstance As New ManagementObject _
            (scope, New ManagementPath("Win32_ComputerSystem.Name='" & _
            ComputerName & "'"), Nothing)

            Dim inParams As ManagementBaseObject = _
            classInstance.GetMethodParameters("Rename")
            inParams("Name") = "NewComputerName"
            inParams("Password") = "xxxxxxxx" 'Local Admin Password
            inParams("UserName") = "xxxxxxxx" 'Local Admin User

            Dim outParams As ManagementBaseObject = _
            classInstance.InvokeMethod("Rename", inParams, Nothing)
            Console.WriteLine("Rename Successful")
        Catch err As ManagementException
            Console.WriteLine("Rename Failed!")
            Console.WriteLine("Error: " & err.Message)
        End Try

        Console.WriteLine("")
        Console.WriteLine("Workstation Must Be Restarted!")


这篇关于重命名远程计算机并将其从域中删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆