VBScript to change windows Administrator password - vbscript

I need a VBScript which can change the windows local administrator password (without asking the previous one) entered by the user...
I found the script which can reset the password but this scripts are not asking to input the password... :(
Please help me on this issue...
Thanks in advance...

This might help:
strComputer = "." ' Local Computer
strUser = "Admin"
SET objUser = GETOBJECT("WinNT://" & strComputer & "/" & strUser)
objUser.Put "PasswordExpired", 1
objUser.SetInfo
strComputer = "." ' Local Computer
strUser = "Administrator"
SET objUser = GETOBJECT("WinNT://" & strComputer & "/" & strUser)
objUser.Put "PasswordExpired", 1
objUser.SetInfo

Related

Vbscript to query computer name and then write to registry HKLM\software dword?

Hi could any one point me in the right direction to create Vbscript to query computer name and then write the query result to registry HKLM\software\test dword or string
this is what i have got so far i just dont know how to link the query then add the query result to the registry -thanks in advance
Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")
strKeyPath = "SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName"
strValueName = "ComputerName"
oReg.GetExpandedStringValue HKEY_LOCAL_MACHINE,strKeyPath, _
strValueName,strValue
From Help https://www.microsoft.com/en-au/download/details.aspx?id=2764
Computername
Set WshNetwork = WScript.CreateObject("WScript.Network")
WScript.Echo "Domain = " & WshNetwork.UserDomain
WScript.Echo "Computer Name = " & WshNetwork.ComputerName
WScript.Echo "User Name = " & WshNetwork.UserName
Write Registry
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.RegWrite "HKCU\Software\ACME\FortuneTeller\", 1, "REG_BINARY"

vbscript group membership & user status

Does anyone know how using vbscript one can query the members of a local group and also return their status ie enabled or disabled?
I have this to get the group membership:
Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName
strGroup = "Users"
Set objGroup = GetObject("WinNT://" & strComputer & "/" & strGroup & ",group")
For Each objMember In objGroup.Members
WScript.Echo objMember.Name
Next
OS = Windows 2008
Try something like this:
For Each objMember In objGroup.Members
If objMember.Class = "User" Then
Set objUser = GetObject("WinNT://" & strComputer & "/" & objMember.Name)
WScript.Echo objUser.Name & " [" & objUser.AccountDisabled & "]"
Else
WScript.Echo objMember.Name
End If
Next

objShell.Run MailTo populate vars

I have a script I’m trying to run that will grab the IP address and Computer name and popup their default mail client. I can’t figure out how to have the mailto grab the variables.. Any help would be much appreciated!
Set objShell = CreateObject("Wscript.Shell")
Set objEnv = objShell.Environment("Process")
strComputer = objEnv("COMPUTERNAME")
strUser = "Scanner.User"
strPass = "SomePassword"
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)
temp = "select IPAddress from Win32_NetworkAdapterConfiguration "& _
"where IPEnabled=TRUE"
temp2 = "winmgmts:{impersonationLevel=impersonate}"
set IPConfigSet = GetObject(temp2).ExecQuery(temp)
for each IPConfig in IPConfigSet
if Not IsNull(IPConfig.IPAddress) then
for i=LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress)
objShell.Run("mailto:MyEmail#address.com&subject=strComputer&body=IPConfig.IPAddress(i)")
Msgbox IPConfig.IPAddress(i)
next
end if
next
You need to use ampersand (VBScript's Concatenation Operator) to generate your mailto URI.
objShell.Run("mailto:MyEmail#address.com&subject=" & strComputer & "&body=" & IPConfig.IPAddress(i))

change password at next logon...vbscript

I have the below code that "should" tick the box for change a local users password at next logon but I keep on getting errors.
The account is already created and on the server locally.
Any help please.
I have to do this in vbscript and not powershell due to older servers in our environment.
Code:
' get computer name
Set oWshNet = CreateObject("WScript.Network" )
sComputerName = oWshNet.ComputerName
'Set Account Testuser Password Expired parameter
Set objUser = GetObject("WinNT:// " & sComputerName & "/Testuser")
objUser.Put "PasswordExpired", 1
objUser.SetInfo
Error:
account.vbs(6, 1) (null): The network path was not found.
*****EDIT***********
Figured it out: (thanks google!)
Set oShell = CreateObject("WScript.Shell")
Const SUCCESS = 0
sUser = "TestUser"
' get the local computername with WScript.Network,
' or set sComputerName to a remote computer
Set oWshNet = CreateObject("WScript.Network")
sComputerName = oWshNet.ComputerName
Set oUser = GetObject("WinNT://" & sComputerName & "/" & sUser)
oUser.Put "PasswordExpired", 1
oUser.SetInfo
oShell.LogEvent SUCCESS, "Password Attribute Changed"
Thanks.
The answer to this was:
Set oShell = CreateObject("WScript.Shell")
Const SUCCESS = 0
sUser = "TestUser"
' get the local computername with WScript.Network,
' or set sComputerName to a remote computer
Set oWshNet = CreateObject("WScript.Network")
sComputerName = oWshNet.ComputerName
Set oUser = GetObject("WinNT://" & sComputerName & "/" & sUser)
oUser.Put "PasswordExpired", 1
oUser.SetInfo
oShell.LogEvent SUCCESS, "Password Attribute Changed"

How to create a user account in Windows Vista using VBScript?

How to create a user account in Windows Vista using VBScript?
I'm using the following script. It's working fine on Windows XP, but gives me an error on Windows Vista:
strUserName = "username"
strPassword = "password"
strComputer = "."
set objSystem = GetObject("WinNT://" & strComputer)
set objUser = objSystem.Create("user", strUserName)
objUser.SetPassword strPassword
objUser.SetInfo
I am able to run this script on my Vista box just fine, and it creates the user.
I suspect you might be having a UAC issue. This article provides some options for elevating the permissions of your script.
Option 1 – the code relaunches itself with elevated permissions:
If WScript.Arguments.length = 0 Then
Set objShell = CreateObject("Shell.Application")
'Pass a bogus argument, say [ uac]
objShell.ShellExecute "wscript.exe", Chr(34) & _
WScript.ScriptFullName & Chr(34) & " uac", "", "runas", 1
Else
'Add your code here
End If
Option 2 – a separate launcher script:
Set objShell = CreateObject("Shell.Application")
Set FSO = CreateObject("Scripting.FileSystemObject")
strPath = FSO.GetParentFolderName (WScript.ScriptFullName)
If FSO.FileExists(strPath & "\MAIN.VBS") Then
objShell.ShellExecute "wscript.exe", _
Chr(34) & strPath & "\MAIN.VBS" & Chr(34), "", "runas", 1
Else
MsgBox "Script file MAIN.VBS not found"
End If

Resources