Join computer to domain using vb.net
-
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 StringDim 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
-
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 StringDim 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
-
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 StringDim 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
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"