Script VBS config IP selon la carte réseau
Bon j ai fait un script vbs qui permet de charger une config ip associée à une carte (choix de la carte possible)
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 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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
| Msgbox "Cette application permet de switcher la config IP de la carte Réseau Ethernet" & chr(13) & _
"entre l'adressage par DHCP et un adressage statique Compatible avec le FSU." & chr(13) & chr(13) & _
"Version de soft : 1.0.1" & chr(13) & "Auteur : Michael VALLET", vbinformation, "Infos"
main
Sub Main
dim strComputer
dim Carte(50)
dim saisie
dim i, j, a
on error resume next
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colNetAdapters = objWMIService.ExecQuery ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
strIPAddress = Array("192.168.11.10")
strSubnetMask = Array("255.255.255.0")
'strGateway = Array("192.168.5.190")
'strDNSServers = Array("97.20.255.254")
strGatewayMetric = Array(1)
carte(0) = ""
i = 1
For Each objNetAdapter in colNetAdapters
carte(i) = objNetAdapter.caption
i = i + 1
Next
i = i - 1
for j = 1 to i
Carte(0) = carte(0) & j & " --> " & carte(j) & chr(13) & chr(13)
next
carte(0) = carte(0) & chr(13) & chr(13) & "Taper E pour ouvrir directement l'explorateur FSU"
saisie = inputbox(carte(0),"Choix de la carte Réseau")
if saisie = "" then exit sub
'if saisie > i then main
if saisie = "E" or saisie = "e" then
Set WshShell = CreateObject("WScript.Shell")
Set oExec = WshShell.Exec("explorer \\192.168.11.11\Dossier_partager")
exit sub
end if
ChoixConfig = inputbox("Quelle config voulez vous charger?" & chr(13) & chr(13) & "1 --> DHCP Alstom" & chr(13) & "2 --> FSU","Choix de la Config IP")
if ChoixConfig = "" then exit sub
if choixConfig > 2 then main
If choixConfig = "1" then
For Each objNetAdapter in colNetAdapters
if objNetAdapter.caption = carte(saisie) then
'msgbox objNetAdapter.caption & " ok, on rentre dans le IF"
errEnable = objNetAdapter.EnableDHCP 'EnableStatic(strIPAddress, strSubnetMask)
'errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
'errDOM = objNetAdapter.EnableDNS'SetDNSServerSearchOrder(strDNSServers)
end if
next
if errEnable = 0 Then
WScript.Echo "L'addresse IP a été changée correctement."
Else
WScript.Echo "L'addresse n'a pas été changée il y a un Pb."
End If
end if
If choixConfig = "2" then
For Each objNetAdapter in colNetAdapters
if objNetAdapter.caption = carte(saisie) then
WScript.Echo "L'ordinateur se connecte. Veuillez quelques secondes...."
errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
'errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
'errDOM = objNetAdapter.EnableDNS'SetDNSServerSearchOrder(strDNSServers)
end if
next
if errEnable = 0 Then
WScript.Echo "L'addresse IP a été changée correctement."
Set WshShell = CreateObject("WScript.Shell")
Set oExec = WshShell.Exec("explorer \\192.168.11.11\Dossier_partager")
Else
WScript.Echo "L'addresse n'a pas été changée il y a un Pb."
End If
end if
end sub |