Précédent   Forum du club des développeurs et IT Pro > Autres langages > Général Visual Basic 6 et VBScript > VBScript
VBScript Le forum d'entraide sur VBScript. Avant de poster -> La FAQ VBScript
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse
 
Outils de la discussion
Publicité
'
Vieux 22/02/2013, 18h02   #1
alexdt256
Invité de passage
 
Homme Alex
Inscription : février 2013
Messages : 3
Détails du profil
Informations personnelles :
Nom : Homme Alex
Localisation : Canada

Informations forums :
Inscription : février 2013
Messages : 3
Points : 0
Points : 0
Par défaut vbs remote rename ne fonctionne pas SVP m'aider

Sa fais presque 1h que j'essai de faire fonctionner mon script pour renommer les pc mais sa me donne toujours l'erreur: Permission denied: 'GetObject' line 11 char 1

Voici la ligne de l'erreur
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Voici mon script :

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
' Input Section
strComputer =InputBox("Old Name?")
sNew =InputBox("New Name?")
sDomainUser ="MyDomain\" & InputBox("Domain Admin Username") 
sDomainPasswd =InputBox("Password (NOT hidden!)") 
sAdminUser =strComputer & "\administrator" 
sAdminPassword ="MyAdminpassword"
 
' Start Remote Registry
strService = " 'RemoteRegistry' "
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strcomputer & "\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery ("Select * from Win32_Service Where Name =" & strService & " ")
For Each objService in colListOfServices
   WSCript.Sleep 1500
   objService.StartService()
Next
WScript.Echo "Started " & strService & " on " & strComputer
 
' Rename strComputer
set oWMILocator = CreateObject("WbemScripting.SWbemLocator")
oWMILocator.Security_.AuthenticationLevel = 6
set oWMIComputer = oWMILocator.ConnectServer(strComputer, "root\cimv2",strComputer & sAdminUser,sAdminPassword)
set oWMIComputerSystem = oWMIComputer.Get("Win32_ComputerSystem.Name='" & strComputer & "'")
 
rc = oWMIComputerSystem.Rename(sNew,sDomainPasswd,sDomainUser)
alexdt256 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 22/02/2013, 18h54   #2
ProgElecT
Rédacteur/Modérateur
 
Avatar de ProgElecT
 
Homme Francis MILLET
Inscription : décembre 2004
Messages : 3 198
Détails du profil
Informations personnelles :
Nom : Homme Francis MILLET
Âge : 57
Localisation : France, Haute Savoie (Rhône Alpes)

Informations professionnelles :
Secteur : Communication - Médias

Informations forums :
Inscription : décembre 2004
Messages : 3 198
Points : 5 110
Points : 5 110
Envoyer un message via MSN à ProgElecT
Salut, bienvenue sur DVP

En ligne 9, peux tu mettre un MsgBox et nous dire ce que tu as exactement dans la variable strComputer
ProgElecT est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 22/02/2013, 19h51   #3
alexdt256
Invité de passage
 
Homme Alex
Inscription : février 2013
Messages : 3
Détails du profil
Informations personnelles :
Nom : Homme Alex
Localisation : Canada

Informations forums :
Inscription : février 2013
Messages : 3
Points : 0
Points : 0
Bonjour,

Pour la variable strcomputer elle change différemment de qu'elle ordinateur je veux changer. C'est pour cette raison que j'ai mis inputbox (Ligne 2). Se que je veux c'est que lorsque sur le réseau je veux changer le nom d'un pc je puisse juste partir se vbs, mettre le nom du pc désiré et mes credential.

Merci pour le bienvenue !
alexdt256 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 22/02/2013, 19h59   #4
ProgElecT
Rédacteur/Modérateur
 
Avatar de ProgElecT
 
Homme Francis MILLET
Inscription : décembre 2004
Messages : 3 198
Détails du profil
Informations personnelles :
Nom : Homme Francis MILLET
Âge : 57
Localisation : France, Haute Savoie (Rhône Alpes)

Informations professionnelles :
Secteur : Communication - Médias

Informations forums :
Inscription : décembre 2004
Messages : 3 198
Points : 5 110
Points : 5 110
Envoyer un message via MSN à ProgElecT
Ok

J'ai l'impression qu’après la récupération dans la variable, il te faudrait ajouter quelque chose du genre .\.
Le plus simple est de lire la variable et analyser si l'inclusion dans la ligne de code serait cohérent.
ProgElecT est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 22/02/2013, 20h10   #5
alexdt256
Invité de passage
 
Homme Alex
Inscription : février 2013
Messages : 3
Détails du profil
Informations personnelles :
Nom : Homme Alex
Localisation : Canada

Informations forums :
Inscription : février 2013
Messages : 3
Points : 0
Points : 0
En exemple si je placerais Exemp-D-0222 comme variable strcomputer. Je ne crois pas que sa changerais grand chose. Sauf si tu vois quelque chose qui me manquerais

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
' Input Section
strComputer ="Exemp-D-0222"
sNew ="Exemp-Corr"
sDomainUser ="MyDomain\" & "Me"
sDomainPasswd =InputBox("Password (NOT hidden!)") 
sAdminUser =strComputer & "\administrator" 
sAdminPassword ="MyAdminpassword"
 
' Start Remote Registry
strService = " 'RemoteRegistry' "
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strcomputer & "\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery ("Select * from Win32_Service Where Name =" & strService & " ")
For Each objService in colListOfServices
   WSCript.Sleep 1500
   objService.StartService()
Next
WScript.Echo "Started " & strService & " on " & strComputer
 
' Rename strComputer
set oWMILocator = CreateObject("WbemScripting.SWbemLocator")
oWMILocator.Security_.AuthenticationLevel = 6
set oWMIComputer = oWMILocator.ConnectServer(strComputer, "root\cimv2",strComputer & sAdminUser,sAdminPassword)
set oWMIComputerSystem = oWMIComputer.Get("Win32_ComputerSystem.Name='" & strComputer & "'")
 
rc = oWMIComputerSystem.Rename(sNew,sDomainPasswd,sDomainUser)
alexdt256 est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse
Outils de la discussion

Navigation rapide


Fuseau horaire GMT +2. Il est actuellement 23h14.


 
 
 
 
Partenaires

Hébergement Web