Davoud Teimouri – Virtualization and Data Center

Add domain user to administrators group on remote machine (VBScript)

We have a support team that they need to our assistance about adding their accounts to local administrators group of some computers. My colleagues have to open “Computer Management”, connect to remote computer and add the user to the group. I don’t like this process.

The below script helps my colleagues, maybe useful for you as well:

'Version 1.0
'Written by Davoud Teimouri
Option Explicit
On Error Resume Next
Dim strComputer
Dim strUser
Dim objGroup
Dim ObjUser
strComputer = Inputbox ("Please enter the computer name (Without domain name):")
strUser= Inputbox ("Please enter the user name:")
strComputer=strComputer & ".Your Domain"
Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators,group")
Set objUser = GetObject("WinNT://Your Domain/" & strUser & ",user")
If Ping(strComputer) Then
    Err.Description=" The target is not reachable."
End If

If Err=0 Then
    Msgbox (strUser & " has been added to administrators group of " & strComputer)
    Err.Description=" Please check the username."
End If

Sub DisplayErrorInfo

    WScript.Echo "An error is occurred." & Err.Description

End Sub

Function Ping(strHost)
    Dim oPing, oRetStatus, bReturn
    Set oPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery("select * from Win32_PingStatus where address='" & strHost & "'")
    For Each oRetStatus In oPing
        If IsNull(oRetStatus.StatusCode) Or oRetStatus.StatusCode <> 0 Then
            bReturn = False
            bReturn = True

        End If
        Set oRetStatus = Nothing
    Set oPing = Nothing
    Ping = bReturn
End Function

Further Reading

Run ESXi Commands Via PowerShell And SSH

Windows 7 USB Sound Problem On PCoIP

How to change the listening port for Remote Desktop

Exit mobile version