Notification

Icon
Error

Script - Create Admin User

Posted: Tuesday, January 6, 2015 1:31:37 PM(UTC)
Bert.D

Bert.D

Member Lansweeper Developer Administration Original PosterPosts: 103
4
Like
Creates a new local user and adds it to the local admin group

Rem: You need to add the user and password as a parameters.
Rem: If you do not add a username parameter, the username is default set to: Lansweeperadm
Rem: If you do not add a password parameter, the password is default set to: Strongpassword0*

Rem: Copy the code below and save it as Create_Admin_User.vbs at the {PackageShare}\Scripts folder

Code:

Set Arg = WScript.Arguments

if Arg.count = 2 then 
  strUser     = Arg(0) 'Pass the username as parameter to the script
  strPassword = Arg(1) 'Pass the password as parameter to the script
end if

if IsEmpty(strUser) or IsNull(strUser) or strUser = "" or IsEmpty(strPassword) or IsNull(strPassword) or strPassword = "" then
  strUser     = "Lansweeperadm"  
  strPassword = "Strongpassword0*"
end if

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

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery ("SELECT Name,SID from Win32_Group where domain ='" & strcomputer & "'")
For Each objItem in colItems
  sidAdmin = objItem.SID
  if sidadmin = "S-1-5-32-544" then
    strGroup = objItem.Name
  end if
Next

Set colAccounts = GetObject("WinNT://" & strComputer & "")
Set objUser = colAccounts.Create("user", strUser)
objUser.SetPassword strpassword
objUser.SetInfo
Set objGroup = GetObject("WinNT://" & strComputer & "/" & strGroup & ",group")
objGroup.Add(objUser.ADsPath)
Script - Create Admin UserDownload Package
DescriptionCreates an new local user and adds it to the local admin group

Rem: You need to add the user and password as a parameters.
Rem: If you do not add a username parameter, the username is default set to: Lansweeperadm
Rem: If you do not add a password parameter, the password is default set to: Strongpassword0*
Final ActionNothing
Max. Duration3 min(s), 0 hour(s)
RescanNo
Steps
1. Check for file
TypeCondition
SuccessGo To Step 2
FailureStop (Failure)
Conditions
File {PackageShare}\Scripts\ Create_Admin_User.vbs Exists
2. Execute script
TypeScript
Return Codes 0,1641,3010
SuccessStop (Success)
FailureStop (Failure)
Command "{PackageShare}\Scripts\Create_Admin_User.vbs" Lansweeperadm Strongpassword0*
gkeys
#1gkeys Member Posts: 8  
posted: 2/11/2015 9:53:40 PM(UTC)
Unfortunately, I am having no success getting this to run on a test machine. Other script installer packages (like change wallpaper) work fine, this one just times out........
Michael.V
#2Michael.V Member Posts: 251  
posted: 2/12/2015 8:42:24 AM(UTC)
Are you able to run the vbs file manually on the client?
gkeys
#3gkeys Member Posts: 8  
posted: 2/12/2015 4:18:43 PM(UTC)
Running locally pointed out the issue. Line 16 & 17 are a split and the VBS compiler on Windows 8.1 did not like it. The lines read:
Set colItems = objWMIService.ExecQuery ("SELECT Name,SID from Win32_Group
where domain ='" & strcomputer & "'")

once I changed it to a single line:
Set colItems = objWMIService.ExecQuery ("SELECT Name,SID from Win32_Group where domain ='" & strcomputer & "'")

Everything ran like a champ.

Bert.D
#4Bert.D Member Lansweeper Developer Administration Original PosterPosts: 103  
posted: 2/12/2015 5:23:19 PM(UTC)
I adjusted the post so others won't have the same issue.

Good catch Applause
gkeys
#5gkeys Member Posts: 8  
posted: 2/12/2015 6:52:13 PM(UTC)
Now my challenge is to modify this so that if the account already exists it just updates the password. My goal is to have the same local admin account on every PC in the domain and to change the password every 30 days.
I am NOT a VB Script person....... learning curves are so much fun.......

Bert.D
#6Bert.D Member Lansweeper Developer Administration Original PosterPosts: 103  
posted: 2/17/2015 2:54:03 PM(UTC)
You could take a look at this post: http://www.lansweeper.com/Forum/yaf_postst10448_Script---Reset-Local-Admin-Password.aspx#post39286

The code there (re)sets the password for the administrator Angel
pixa241
#7pixa241 Member Posts: 8  
posted: 6/3/2015 8:33:56 PM(UTC)
Can this be used with thin clients, and will it recognize variables? Our local admin on thin clients has a unique password like my%hostname%password. Could that be used to pass on the username and password? and if I do not want the new user to be a local admin as well?
Bert.D
#8Bert.D Member Lansweeper Developer Administration Original PosterPosts: 103  
posted: 6/5/2015 3:54:04 PM(UTC)
You need to look up the hostname inside the script and add it to your password.

If you don't want him to be admin you should remove the part where the user is added to the admin group.
spamking
#9spamking Member Posts: 16  
posted: 6/22/2016 1:12:14 PM(UTC)
Can this be modified to set the password for the new admin account to never expire? We have had a few machines fall off of our domain due to inactivity or other errors and would like at least one account with a password set to never expire.
Zacs
#10Zacs Member Posts: 23  
posted: 8/16/2017 11:37:04 AM(UTC)
Hi Guys

I have followed this but when i try do it i get a access denied message
Line: 28
Char: 1
Error: Access denied

Code: 8007005
Source: Active directory

I have run as system
I have run as scanning cred(Domain Admin)

But its both the same

HELP!!!!

Active Discussions

Lansweeper Laptop warranty include users from active directory filtered by OU
by  Iyad   Go to last post Go to first unread
Last post: Yesterday at 11:09:27 PM(UTC)
Lansweeper Exclude Search
by  pryan67  
Go to last post Go to first unread
Last post: Yesterday at 4:01:43 PM(UTC)
Lansweeper Report: All Apple Mac devices with Memory RAM asset
by  gabrielo   Go to last post Go to first unread
Last post: Yesterday at 3:17:24 PM(UTC)
Lansweeper Does technical support for LS really respond?
by  tosch  
Go to last post Go to first unread
Last post: Yesterday at 12:48:50 PM(UTC)
Lansweeper Deployment packages using lsagent
by  CyberCitizen   Go to last post Go to first unread
Last post: 6/15/2021 11:44:33 PM(UTC)
Lansweeper INFO DateTimeService time refresh
by  ZachO21  
Go to last post Go to first unread
Last post: 6/15/2021 4:23:15 PM(UTC)
Lansweeper Helpdesk tabs always regenarated
by  Carla   Go to last post Go to first unread
Last post: 6/14/2021 9:49:27 PM(UTC)
Lansweeper Importing with user relations
by  teddyh2o  
Go to last post Go to first unread
Last post: 6/14/2021 6:05:46 PM(UTC)