TUTOS.EU

Modifier le mot de passe du compte admin local

Modifier en VbScript le mot de passe du compte local de l'administrateur

Dim strComputer, objUser, strUser, strPassword
Dim WSHShell
Dim vUSERDOMAIN, vCOMPUTERNAME
Dim AdminNameFound

'Definition du nouveau mot de passe du compte administrateur
strPassword = "Password" 

Set WSHShell = CreateObject("WScript.Shell")
vUSERDOMAIN = WSHShell.ExpandEnvironmentStrings("%USERDOMAIN%")
vCOMPUTERNAME = WSHShell.ExpandEnvironmentStrings("%COMPUTERNAME%")

'strComputer = "."
strComputer = vCOMPUTERNAME
Wscript.echo "strComputer : " & strComputer

strUser = "Administrator"
AdminNameFound = 0

Err.Clear
On Error Resume Next
Set objUser = GetObject("WinNT://" & strComputer & "/" & strUser)

If Err.Number = 0 Then
	AdminNameFound = 1
Else
	strUser = "Administrateur"
	Err.Clear
	On Error Resume Next
	Set objUser = GetObject("WinNT://" & strComputer & "/" & strUser)
	If Err.Number = 0 Then AdminNameFound = 1
End If

If AdminNameFound = 1 Then
	'Deverrouillage preventif du compte
	Err.Clear
	objUser.IsAccountLocked = False
	objUser.SetInfo
	Wscript.echo "Erreur ? : " & Err.number
	On Error GoTo 0
	Set objUser = Nothing

	'Modification du mot de passe
	strDomain = strComputer

	On Error Resume Next
	Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
	Set objSWbemServices = objSWbemLocator.ConnectServer(strComputer, "root\cimv2", strUser, strPassword, "MS_409", "ntlmdomain:" + strDomain)
	NumeroErreur = Err.Number
	On Error GoTo 0

	Wscript.echo "Modification du mot de passe de " & strUser & " ? : " & Err.number
	If NumeroErreur = 0 Then
		'Test
	End If

	Set objSWbemServices = Nothing
	Set objSWbemLocator = Nothing
	
Else
	Wscript.echo "Admin account name not found"
End If

Set WSHShell = Nothing

Lien vers le fichier : cliquez ici