Bonjour,

Je dois faire un script pour sauvegarder la conf réseau dans un fichier et un second pour restaurer la conf réseau à partir du fichier.
La première partie fonctionne tant bien que mal avec ce script :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
Set objFSO = CreateObject("Scripting.FileSystemObject") 
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colAdapters = objWMIService.ExecQuery _
("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
n = 1
For Each objAdapter in colAdapters
strFileName="c:/logs/settings1.txt"
Set objFile=objFSO.CreateTextFile(strFileName, true) 
objFile.WriteLine "Carte  réseau n° " & n
objFile.WriteLine "Description: " & objAdapter.Description
objFile.WriteLine "MAC  address: " & objAdapter.MACAddress
objFile.WriteLine "Host name: " & objAdapter.DNSHostName
If Not IsNull(objAdapter.IPAddress) Then
For i = 0 To UBound(objAdapter.IPAddress)
objFile.WriteLine "Addresse IP : " & objAdapter.IPAddress(i)
Next
End If
If Not IsNull(objAdapter.IPSubnet) Then
For i = 0 To UBound(objAdapter.IPSubnet)
objFile.WriteLine "   Masque: " & objAdapter.IPSubnet(i)
Next
End If
If Not IsNull(objAdapter.DefaultIPGateway) Then
For i = 0 To UBound(objAdapter.DefaultIPGateway)
objFile.WriteLine " Passerelle : " & _
objAdapter.DefaultIPGateway(i)
Next
End If
objFile.WriteLine "Domaine DNS: " & objAdapter.DNSDomain
If Not IsNull(objAdapter.DNSDomainSuffixSearchOrder) Then
For i = 0 To UBound(objAdapter.DNSDomainSuffixSearchOrder)
objFile.WriteLine "DNS suffix search list: " & _
objAdapter.DNSDomainSuffixSearchOrder(i)
Next
End If
objFile.WriteLine "Poste en DHCP?: " & objAdapter.DHCPEnabled
objFile.WriteLine "Serveur DHCP: " & objAdapter.DHCPServer
If Not IsNull(objAdapter.DHCPLeaseObtained) Then
utcLeaseObtained = objAdapter.DHCPLeaseObtained
strLeaseObtained = WMIDateStringToDate(utcLeaseObtained)
Else
strLeaseObtained = ""
End If
objFile.WriteLine "Date du bail DHCP: " & strLeaseObtained
If Not IsNull(objAdapter.DHCPLeaseExpires) Then
utcLeaseExpires = objAdapter.DHCPLeaseExpires
strLeaseExpires = WMIDateStringToDate(utcLeaseExpires)
Else
strLeaseExpires = ""
End If
objFile.WriteLine "Expiration du bail DHCP: " & strLeaseExpires
objFile.WriteLine "Serveur WINS: " & objAdapter.WINSPrimaryServer
n = n + 1
Next
Function WMIDateStringToDate(utcDate)
WMIDateStringToDate = CDate(Mid(utcDate, 5, 2) & "/" & _
Mid(utcDate, 7, 2) & "/" & _
Left(utcDate, 4) & " " & _
Mid (utcDate, 9, 2) & ":" & _
Mid(utcDate, 11, 2) & ":" & _
Mid(utcDate, 13, 2))
End Function
J'ai une erreur "Permission refusée" à la ligne "Set objFile=objFSO.CreateTextFile(strFileName, true)" ce qui n'empêche pas le fichier de se créer et de prendre les bonnes infos.

Et de plus j'avoue ne pas savoir par quel bout prendre le script qui va restaurer la conf réseau

Toute aide ou piste sera la bienvenue.

PS: Pour ceux qui se poserait la question, j'ai auparavant essayer avec la commande netsh dump mais sous windows 7 elle ne récupère et restaure pas toutes les infos de la conf.

Keely