Created
November 26, 2014 10:17
-
-
Save muthuishere/13a37deead6ebaf38a77 to your computer and use it in GitHub Desktop.
This Script creates New User and add it to administrator group in windows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'This Script creates New User and add it to administrator group in windows | |
'Change the variables strUser & strPass | |
'By default it will run as elevated privileages. | |
Set WshShell = WScript.CreateObject("WScript.Shell") | |
If WScript.Arguments.length = 0 Then | |
Set ObjShell = CreateObject("Shell.Application") | |
ObjShell.ShellExecute "wscript.exe", """" & _ | |
WScript.ScriptFullName & """" &_ | |
" RunAsAdministrator", , "runas", 1 | |
WScript.Quit | |
End if | |
strUser = "YOUR_USERNAME" | |
strPass = "YOUR_PASSWORD" | |
Set objShell = CreateObject("Wscript.Shell") | |
Set objEnv = objShell.Environment("Process") | |
strComputer = objEnv("COMPUTERNAME") | |
Set colAccounts = GetObject("WinNT://" & strComputer & ",computer") | |
Set objUser = colAccounts.Create("user", strUser) | |
objUser.SetPassword strPass | |
Const ADS_UF_DONT_EXPIRE_PASSWD = &h10000 | |
objPasswordExpirationFlag = ADS_UF_DONT_EXPIRE_PASSWD | |
objUser.Put "userFlags", objPasswordExpirationFlag | |
objUser.SetInfo | |
Set Group = GetObject("WinNT://" & strComputer & "/Administrators,group") | |
Group.Add(objUser.ADspath) | |
Set Group = GetObject("WinNT://" & strComputer & "/Users,group") | |
Group.Add(objUser.ADspath) | |
Wscript.echo "Successfully Created admin for" & strUser |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment