J'ai écrit un petit script qui, à partir d'un tableau excel contenant un certain nombre d'informations devrait effectuer la réservation d'une adresse IP au niveau DHCP.
Set objExcel = CreateObject("Excel.Application" ) Set objWorkbook = objExcel.Workbooks.Open("C:\IP2.xls" ) Set objShell = WScript.CreateObject("WScript.Shell" ) Set WshShell = WScript.CreateObject("Wscript.Shell" )
intRow = 2
Do Until objExcel.Cells(intRow, 1).Value = ""
descript = objExcel.Cells(intRow, 1).Text mac = objExcel.Cells(intRow, 3).Text id = objExcel.Cells(intRow, 5).Text finip = objExcel.Cells(intRow, 6).Text ip = "142.50." & id & "." & finip
ligne = "cmd.exe /K netsh dhcp server scope 142.50.0.0 add reservedip " & ip & " " & mac & " " & descript" 'Wscript.Echo " " &ligne objShell.Run(&ligne) intRow = intRow + 1 Loop
objExcel.Quit
Malheureusement, la commande ne s'éxecute pas. Pire, lorsque j'execute directement la ligne de commande dans une fenêtre DOS, tout se passe correctement et l'IP est bien réservée.
J'ai essayé un certain nombre de manip dont 'objShell.Run ("cmd.exe /K &ligne" ) (avec la modif qui va bien au niveau de ligne), pour le même résultat.
Marsh Posté le 15-09-2006 à 16:12:35
Bonjour à tous,
J'ai écrit un petit script qui, à partir d'un tableau excel contenant un certain nombre d'informations devrait effectuer la réservation d'une adresse IP au niveau DHCP.
Set objExcel = CreateObject("Excel.Application" )
Set objWorkbook = objExcel.Workbooks.Open("C:\IP2.xls" )
Set objShell = WScript.CreateObject("WScript.Shell" )
Set WshShell = WScript.CreateObject("Wscript.Shell" )
intRow = 2
Do Until objExcel.Cells(intRow, 1).Value = ""
descript = objExcel.Cells(intRow, 1).Text
mac = objExcel.Cells(intRow, 3).Text
id = objExcel.Cells(intRow, 5).Text
finip = objExcel.Cells(intRow, 6).Text
ip = "142.50." & id & "." & finip
ligne = "cmd.exe /K netsh dhcp server scope 142.50.0.0 add reservedip " & ip & " " & mac & " " & descript"
'Wscript.Echo " " &ligne
objShell.Run(&ligne)
intRow = intRow + 1
Loop
objExcel.Quit
Malheureusement, la commande ne s'éxecute pas. Pire, lorsque j'execute directement la ligne de commande dans une fenêtre DOS, tout se passe correctement et l'IP est bien réservée.
J'ai essayé un certain nombre de manip dont 'objShell.Run ("cmd.exe /K &ligne" ) (avec la modif qui va bien au niveau de ligne), pour le même résultat.
Si quelqu'un a une idée, je suis preneur...
Merci