VB Script = Add User to the local Machine

Posted on 2007-10-09
Last Modified: 2012-06-21
For some reason this script may be old.. Does the job when i add the computer to the local admin groups on the computer. But now each time the computer boots up, the script runs .. how can i hide the script giving the error message or adjust it that it works properly

I have this script as a startup script from my AD 2003 - basically adding the Administrator from the OU to the local admin acocunt on the computer.

Dim oGrpLocal
On Error Resume Next
Set oGrpLocal = GetObject ("WinNT://./administrators,group")
If err.Number <> 0 then
End If
'The DOMAIN below is the netbios domain name, and OULocalAdmins is the name of the group you
'want to add to the local administrators group.
If Not oGrpLocal.IsMember("WinNT://DOMAIN/OULocalAdmins") Then
   oGrpLocal.Add "WinNT://DOMAIN/OULocalAdmins"
End If
Question by:shoris
    1 Comment
    LVL 12

    Accepted Solution


    Try this script.........
    Change the domain name

    Option Explicit

    Dim strDomain, objNetwork, strComputer
    Dim objLocalGroup, objDomainGroup

    ' Specify the NetBIOS name of the domain.
    strDomain = "MyDomain"

    ' Retrieve NetBIOS name of local computer.
    Set objNetwork = CreateObject("Wscript.Network")
    strComputer = objNetwork.ComputerName

    ' Bind to local Administrators group.
    Set objLocalGroup = GetObject("WinNT://" & strComputer _
    & "/Administrators,group")

    ' Bind to domain group.
    Set objDomainGroup = GetObject("WinNT://" & strDomain & "/OULocalAdmins,group")

    ' Check if the domain group is already a member of the local group.
    If Not objLocalGroup.IsMember(objDomainGroup.AdsPath) Then
    ' Add the domain group to the local group.
    End If

    ' Clean up.
    Set objNetwork = Nothing
    Set objLocalGroup = Nothing
    Set objDomainGroup = Nothing

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
    Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now