Solved

How can I create and add a Local Admin to 2000 and XP Machines via Script?

Posted on 2006-06-27
10
273 Views
Last Modified: 2010-04-18
I want to create a generic User acct that is not on the domain and assign it to the local admins group on each computer and assign it a password "x" that does not change? How can I accomplish this task? the script will be applied Via GPO .
0
Comment
Question by:tattsnyc
  • 3
  • 3
  • 2
  • +1
10 Comments
 
LVL 51

Accepted Solution

by:
Netman66 earned 250 total points
ID: 16994164
Place this in your CMD file:

net user Admin Password1 /ADD
net localgroup Administrators Admin /ADD


Replace Password1 with a password of your choice.
Replace Admin with the username of your choice.

0
 
LVL 70

Assisted Solution

by:Chris Dent
Chris Dent earned 250 total points
ID: 16994223

Happy with VbScript? All commented, just yell if it's not clear.

Chris


Const ADS_UF_DONT_EXPIRE_PASSWD = &H10000

strUserName = "AdminUser"
strPassword = "AdminPassword1"

Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName

booExists = False
Set objComputer = GetObject("WinNT://" & strComputer)
For Each objUser In objComputer

      ' If the user exists then just change the password to the one we like

      If (LCase(objUser.Name) = LCase(strUserName)) Then
            booExists = True
            objUser.SetPassword strPassword
            objUser.SetInfo
      End If
Next

' If it doesn't exist create the user and set the password.

If booExists = False Then
      Set objUser = objComputer.Create("user", strUserName)
      objUser.SetPassword strPassword
      objUser.SetInfo

      Set objUser = GetObject("WinNT://" & strComputer & "/" & strUserName & ",user")
      objUser.Description = "Admin Account"

      ' Set the Password to Never Expire

      If Not objUser.UserFlags AND ADS_UF_DONT_EXPIRE_PASSWD Then
            intUserFlags = objUser.UserFlags XOr ADS_UF_DONT_EXPIRE_PASSWD
            objUser.Put "userFlags", intUserFlags
      End If
      objUser.SetInfo

      ' Add the user to the Administrators Group

      Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators, group")
      objGroup.Add(objUser.ADsPath)
      Set objGroup = Nothing
      Set objUser = Nothing
End If
0
 
LVL 51

Expert Comment

by:Netman66
ID: 16994244
Nice script Chris.

Kinda makes me laugh a bit though - it's like the difference between mine in English and yours being the French translation!

0
 
LVL 70

Expert Comment

by:Chris Dent
ID: 16994717

Hehe I see what you mean, the only difference is the password never expires thing, and that's hardly a huge chunk.

I kind of stopped bothering to learn dos commands so half the stuff I do could probably be done in a few lines if I learnt that too :)

Chris
0
 
LVL 16

Expert Comment

by:kshays
ID: 16995468
There are plenty of dos commands for a system admin especially if you utilize the resource kit.  I do think both vbscript and dos commands have a place for in any sys admins library, sometimes it's just easier to do it the old school way :)

Then again you can do some things with vbscript i'm sure that you cannot do with dos commands.

just my two scents on the subject :)

0
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 

Author Comment

by:tattsnyc
ID: 16995500
I want to split the points between the first two commenters any objections? thanks for all you help
0
 
LVL 16

Expert Comment

by:kshays
ID: 16995516
I would probably split points between netman66 and chris-dent as well tattsync.  Seems like the only fair thing to do really since both posted a solution that would fit your needs either way and the time was so close to each other.
0
 
LVL 51

Expert Comment

by:Netman66
ID: 16996273
I have no problem with that.
0
 
LVL 70

Expert Comment

by:Chris Dent
ID: 16996944

No problems here either :)

Chris
0
 

Author Comment

by:tattsnyc
ID: 17156116
sorry about the dely. I  am so busy I forgot.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I've always wanted to allow a user to have a printer no matter where they login. The steps below will show you how to achieve just that. In this Article I'll show how to deploy printers automatically with group policy and then using security fil…
A quick step-by-step overview of installing and configuring Carbonite Server Backup.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

867 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

18 Experts available now in Live!

Get 1:1 Help Now