Datamation Logo

Script to add domain user account to local Administrators group

September 25, 2003
Datamation content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More .

Want to share a script? Click here to contribute!

Author:
Rod Trent – rtrent [at] swynk [dot] com

Platform:
Windows NT (with WSH 2.0 from http://msdn.microsoft.com/scripting and WMI 1.1 from http://msdn.microsoft.com/downloads/sdks/wmi/)
Windows 2000

Type:
WSH
VBScript
JScript ADSI logon/logoff
startup/shutdown

Description:
This VB Script adds a domain user account to the local machine’s administrators group. There are two variables that need to be changed in the script to match the organization. The first is the DomainName variable, and the second is the UserAccount variable. Save as a .VBS script and run with CScript.

Scroll down to view the script.


Script to add domain user account to local Administrators group


Dim DomainName
Dim UserAccount
Set net = WScript.CreateObject("WScript.Network")
local = net.ComputerName
DomainName = "DomainName"
UserAccount = "userAccount"

set group = GetObject("WinNT://"& local &"/Administrators")

on error resume next
group.Add "WinNT://"& DomainName &"/"& UserAccount &""
CheckError

sub CheckError
	if not err.number=0 then
	set ole = CreateObject("ole.err")
	MsgBox ole.oleError(err.Number), vbCritical
	err.clear
else
	MsgBox "Done."
end if
end sub

Disclaimer: We hope that the information in these pages is valuable to you. Your use of the information contained in these pages, however, is at your sole risk. All information on these pages is provided “as -is”, without any warranty, whether express or implied, of its accuracy, completeness, fitness for a particular purpose, title or non-infringement, and none of the third-party products or information mentioned in the work are authored, recommended, supported or guaranteed by me. I shall not be liable for any damages you may sustain by using this information, whether direct, indirect, special, incidental or consequential, even if it has been advised of the possibility of such damages.

  SEE ALL
APPLICATIONS ARTICLES
 

Subscribe to Data Insider

Learn the latest news and best practices about data science, big data analytics, artificial intelligence, data security, and more.

Datamation Logo

Datamation is the leading industry resource for B2B data professionals and technology buyers. Datamation's focus is on providing insight into the latest trends and innovation in AI, data security, big data, and more, along with in-depth product recommendations and comparisons. More than 1.7M users gain insight and guidance from Datamation every year.

Advertisers

Advertise with TechnologyAdvice on Datamation and our other data and technology-focused platforms.

Advertise with Us

Our Brands


Privacy Policy Terms & Conditions About Contact Advertise California - Do Not Sell My Information

Property of TechnologyAdvice.
© 2025 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.