VBS: Add domain user and group to local administrators

I have a piece of VBS code that I have modified that basically adds a specified domain user and group to the PCs local Administrators group. It works on Windows 7, but not on Windows 8 at all.

Call AddUserToGroup("./Administrators", "myDomain.net/NetworkAdminis")
Call AddUserToGroup("./Administrators", "myDomain.net/Domain Admins")
Call addDomainUser("myDomain", "myUserGroup")


Sub AddUserToGroup(local, domain)
	On Error Resume Next

	Dim objLocalGroup
	Dim objDomainGroup
	Dim server
	
	For Each server in servers
		Set objLocalGroup = GetObject("WinNT://" & local & ",group")
		Set objDomainGroup = GetObject("WinNT://" & domain & ",group")
		With objLocalGroup
			.Add(objDomainGroup.AdsPath)
			.SetInfo
		End With			
	Next

	Set objLocalGroup = Nothing
	Set objDomainGroup = Nothing

End Sub


Sub addDomainUser(strDomain, strUser)
   
    Dim strComputer
    Dim objWshNet
    Dim objGroup
    Dim objUser
    
    Set objWshNet = CreateObject("WScript.Network")
    strComputer = objWshNet.ComputerName
    Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators,group")
    Set objUser = GetObject("WinNT://" & strDomain & "/" & strUser & ",user")
    If Not objGroup.IsMember(objUser.ADsPath) Then
        objGroup.Add (objUser.ADsPath)
    End If
    
    Set objWshNet = Nothing
    Set objGroup = Nothing
    Set objUser = Nothing
    
End Sub

I have debugged the code line by line using VBA's IDE and there seems to be no error condition firing. It executes all lines, but it is not adding the users and groups as it did with Windows 7 and below. The script is being run as local administrator.
  • Edited by Rick131 19 hours 43 minutes ago
April 27th, 2015 7:22pm

Hi Rick131,

This catalog is concentrating on  Windows 8.1 network issue .Considering this issue is more likely a script issue .It is recommended to aks for help from our script forum .They are more familiar with the script issue .Thanks for your understanding and cooperation.
Script Center
https://social.technet.microsoft.com/Forums/scriptcenter/en-US/home?category=scripting

Best regards

Free Windows Admin Tool Kit Click here and download it now
April 28th, 2015 10:36pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics