Pour les besoins du travail j'ai eu besoin de modifier plusieurs clef de registre sur les ordinateurs de mon domaine un des pré requis était qu'il ne fallait rien installer sur les postes cibles.
Je me suis tourné vers WMI pour trouver cette solution :
Dans cette exemple je modifie le nom de connexion par défaut d'une machine distante
Code : Tout sélectionner
Const $HKEY_LOCAL_MACHINE = 0x80000002 ; déclaration de la constante du premier nœud cf plus bas
$strComputer = Nomdelamachinecible ;IP ou nom de la machine cible
$objReg = ObjGet("winmgmts://" & $strComputer & "/root\default:StdRegProv")
$strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
$ValueName = "DefaultUserName"
$strvalue = ""
$return = $objReg.GetStringValue($HKEY_LOCAL_MACHINE,$strKeyPath,$ValueName,$strValue)
If $strValue= "" Then
msgbox(0,"WMIGetStringTest", " introuvable ou null.")
Else
msgbox(0,"WMIGetStringTest","valeur de la clef: " & @CRLF & $strValue)
EndIf
$soluce = $objReg.SetStringValue($HKEY_LOCAL_MACHINE,$strKeyPath, "DefaultUserName","Yogui")
$objReg.GetStringValue($HKEY_LOCAL_MACHINE,$strKeyPath,$ValueName,$strValue)
If $strValue= "" Then
msgbox(0,"WMIGetStringTest", " introuvable ou null.")
Else
msgbox(0,"WMIGetStringTest","valeur de la clef: " & @CRLF & $strValue)
EndIf
J'espère que ça pourra servir un jour à l'un d'entre nous0x80000000 HKEY_CLASSES_ROOT
0x80000001 HKEY_CURRENT_USER
0x80000002 HKEY_LOCAL_MACHINE
0x80000003 HKEY_USERS
0x80000005 HKEY_CURRENT_CONFIG
0x80000006 HKEY_DYN_DATA