Error DataBase-One Place all Solutions Forums Blog Glossary    Contact Us
Search  
   
Browse by Category
Error DataBase-One Place all Solutions .: Operating Systems .: Windows Operating Systems .: Windows Scripts and Batch Files .: VB Script to Add Domain User to Local Administrators - Requires Local Admin Rights

VB Script to Add Domain User to Local Administrators - Requires Local Admin Rights

 

Description: Takes a domain user account and adds it to the local administrators group on a PC

Option Explicit

On Error Resume Next

'Define Variables
Dim CompName, objGroup, objUser, OSName, WshShell

' Set up an Instance of the WScript.Shell Object
Set WshShell = CreateObject("WScript.Shell")

'set access to Env vars
CompName = WshShell.ExpandEnvironmentStrings("%ComputerName%")
OSName = WshShell.ExpandEnvironmentStrings("%OS%")

' If Windows 9x - Then Quit
IF NOT OSName = "Windows_NT" Then
WScript.Quit
End If

' Access Local Admin Group
Set objGroup = GetObject("WinNT://" & CompName & "/Administrators")

' Access Domain User SOE/Deploy
Set objUser = GetObject("WinNT://ChangetoDomainName/ChangeToRequiredUserName")

' Use ADsPath Method to add user: objUser to Local Admin group: objgroup
objGroup.Add(objUser.ADsPath)

Set CompName=Nothing
Set objGroup=Nothing
Set objUser=Nothing
Set OSname=Nothing

WScript.Quit


How helpful was this article to you?

Related Articles

article VB Script to Block The Installation of XP Service Pack 2 - Requires Local Admin Rights
  Description: Blocks the...

(No rating)  3-24-2008    Views: 168   
article Add VBScript to New File Context Menu - Requires Local Admin Rights
  filetype = ".vbs" '...

(No rating)  3-24-2008    Views: 148   
article VB Script to Check if Local User account Exists
  Description: Checks to see if a...

(No rating)  3-24-2008    Views: 158   

User Comments

Add Comment
No comments have been posted.