Occasionally you may need to add a local user account to the local administrators group for a software install or temporary maintenance. The following vbs script can be used to add the local ‘user1’ account to the local ‘administrators’ group. Any user can be added to any local group, change the red to match your needs. The computer name is pulled from the workstation dynamically so this is also completely portable and can be run on any computer.
Set objWSHNetwork = WScript.CreateObject(“WScript.Network”)
strComputerName = objWSHNetwork.ComputerName
Set objComputer = GetObject(“WinNT://” & strComputerName)
Set objGroup = GetObject(“WinNT://” & strComputerName & “/Administrators“)
Set objUser = GetObject(“WinNT://” & strComputerName & “/user1“)
objGroup.Add(objUser.ADsPath)
objUser.SetInfo
To use this through Kaseya save the above as user1addadmin.vbs and upload it to the server:
Script Description: Adds the local user1 account to the local admin group
IF True
THEN
Write File
Parameter 1 : c:\temp\user1addadmin.vbs
Parameter 2 : admin\VBS\user1addadmin.vbs
OS Type : 0
Execute File
Parameter 1 : c:\WINDOWS\system32\wscript.exe
Parameter 2 : c:\temp\user1addadmin.vbs
Parameter 3 : 3
OS Type : 0
ELSE
It might also come up that you may need to remove a user from a local group. The following one line batch file can be run as a login script, batch file or ran as a shell command. It will remove the local ‘user1’ account from the local ‘administrators’ group. Again this will work for any user account and any group. Just change the red to match your needs.
Through Kaseya the following script would accomplish this:
Script Description: removes the local user1 account from the admin group.
IF True
THEN
Execute Shell Command
Parameter 1 : NET LOCALGROUP administrators user1 /delete
Parameter 2 : 1
OS Type : 0
ELSE