Hi Everyone,

How are we all? Im pretty new to vb.net but have worked with alot of vbs scripts. I have used vb scripts in past that prompts to change a computer name & joins it to a inputed domain name... i am currently working on little app in .net that changes a computer name then joins it to a domain. i have done abit of look around on MSDN (http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/67e679cd-e6ba-4a8a-b9c0-6c402af860d4) & other forums finding informtion on how to join a computer to the domain using the system.management.managementobjects....i have also looked in to call Windows Scripting Host (WSH) but can anyone point me in the right direction (Codewise) to achieve the following in an app:

  • Change Computer Name
  • Join to a desired domain
  • use AD Authentication

i am currently using the code to join computer to a Domain, Could u pleas

Dim args(4) As String 
        'Dim args2(2) As String 
 
        Dim retVal As Long 
        Dim comp As System.Management.ManagementObject 
        Dim comps As System.Management.ManagementObjectCollection 
        Dim clsComps As New System.Management.ManagementClass("Win32_ComputerSystem") 
        comps = clsComps.GetInstances() 
        For Each comp In comps 
            'This is used to unjoin the domain 
            ''args2(0) = "Password" 
            ''args2(1) = "User with privs" 
            ''args2(2) = "0" 
            ''comp.InvokeMethod("UnjoinDomainOrWorkgroup", args2) 
 
            'this is used to join the domain 
            args(0) = txtdomain.text 'Took out our FQDN for this posting
            args(1) = "txtpassword.text 'I took the password info out for this posting
            args(2) = txtadminaccount 'I changed the admin account info for this posting
            args(3) = "ou=Workstations" 
            args(4) = 1 
            For x = 0 To 4 
                'read back each value for debugging 
                MsgBox(CStr(args(x))) 
            Next 
            retVal = comp.InvokeMethod("JoinDomainOrWorkgroup", args) 
        Next 
        Return retVal

If you could assist much would be appreicated.

Regards

Forget the WMI :)

.NET has System.DirectoryServices namespace that provides all the AD services you'll need. See the documentation in MSDN.

HTH

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.