[VBS] Changement description ordinateur à distance
Bonjour,
J'ai récupéré un code source VBS permettant de renommer à distance la description d'un ordinateur d'un domaine.
Lien : http://kbshi.wordpress.com/2011/04/1...ne-a-distance/
J'ai donc modifié une partie du code mais lors de l'exécution j'ai un message d'erreur m'indiquant que je n'ai pas les permissions WMI pour faire une modification à distance.
Voici le
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| Dim strDescription, strComputer, reg, objRegistry
Dim ret, msg, ValueName
Const HKLM = &H80000002
strComputer = inputbox("Nom de l'ordinateur cible :")
if strComputer = " " then wscript.quit
on error resume next
Set reg = GetObject(" winmgmts:\\ "& strComputer &" \root\default:StdRegProv ")
if err.number <> 0 then
msgbox "Erreur rencontré en essayant de se connecter à la base de données WMI du '" & strComputer & "'. L'ordinateur est-il sous tension ? Si oui, il peut y avoir un problème avec vos permissions. ",16, "Erreur de connexion au " & strComputer & "."
wscript.quit
end if
on error goto 0
Set objRegistry = GetObject(" winmgmts:{impersonationLevel=impersonate}!\\ " & strComputer & " \root\cimv2?).ExecQuery("" Select Description FROM Win32_OperatingSystem")
For Each object In objRegistry
strDescription = object.Description
Next
value = inputbox(" Description pour l'ordinateur " & strComputer & " : ", "Entrez une nouvelle description ",strDescription)
If value = strDescription then wscript.quit
key = " SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters "
ValueName = " srvcomment "
If Len(Value) > 48 Then Value = Left(Value, 48)
ret = reg.SetStringValue(HKLM, key, ValueName, value)
if ret <> 0 then msgbox " La mise à jour à distance a échoué. " |
Voici ce qui est indiqué sur le site :
‘Prompts for computer name, then retrieves current computer description
‘ Populates inputbox with description, allowing you to overwrite the current
‘ setting. XP, 2003 and below require a restart of the computer or server
‘ service to be restarted in order for the new name to take.
‘
‘Windows Vista/7 seems to take the change immediately.
‘
‘You must have remote registry and WMI permissions to make changes.
‘
‘The script will truncate to the first 48 characters of the description
‘ given in the inputbox.
Je vous remercie par avance.
Information supplémentaire
La partie qui bloque est la suivante :
Code:
1 2 3 4 5 6
| Set reg = GetObject(" winmgmts:\\ "& strComputer &" \root\default:StdRegProv ")
if err.number <> 0 then
msgbox "Erreur rencontré en essayant de se connecter à la base de données WMI du '" & strComputer & "'. L'ordinateur est-il sous tension ? Si oui, il peut y avoir un problème avec vos permissions. ",16, "Erreur de connexion au " & strComputer & "."
wscript.quit
end if
on error goto 0 |
Je vois dans les composants WMI "\root\default" mais pas le sous composant "StdRegProv".