Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. Join computer to domain using vb.net

Join computer to domain using vb.net

Scheduled Pinned Locked Moved .NET (Core and Framework)
csharphelp
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SIFNOk
    wrote on last edited by
    #1

    Hi All, Im developing a app that joins a computer to a domain, but having trouble implementing it using vb.net, any one assist or had the same issue. Much would be appericatied. Regards Dave Below is the code i have so far to join a computer to a domain :S

    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
    
    A R 2 Replies Last reply
    0
    • S SIFNOk

      Hi All, Im developing a app that joins a computer to a domain, but having trouble implementing it using vb.net, any one assist or had the same issue. Much would be appericatied. Regards Dave Below is the code i have so far to join a computer to a domain :S

      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
      
      A Offline
      A Offline
      Abhinav S
      wrote on last edited by
      #2

      SIFNOk wrote:

      trouble

      You have not posted anything about this 'trouble'. Are you getting any errors?

      My signature "sucks" today

      1 Reply Last reply
      0
      • S SIFNOk

        Hi All, Im developing a app that joins a computer to a domain, but having trouble implementing it using vb.net, any one assist or had the same issue. Much would be appericatied. Regards Dave Below is the code i have so far to join a computer to a domain :S

        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
        
        R Offline
        R Offline
        Rob Branaghan
        wrote on last edited by
        #3

        According to the website where it appears you got the code from in the first place, they state that the computer will need to be rebooted for it to take effect. Does it work after pc reboots? http://www.tek-tips.com/viewthread.cfm?qid=1119264&page=1[^]

        Visit my personal site @ http://www.love2code.co.uk .NET Developer @ FactoryMaster Ltd "Software for TOUGH businesses"

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups