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 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
| 'Run as Admin
If Not WScript.Arguments.Named.Exists("elevate") Then
CreateObject("Shell.Application").ShellExecute DblQuote(WScript.FullName) _
, DblQuote(WScript.ScriptFullName) & " /elevate", "", "runas", 1
WScript.Quit
End If
Titre = "Renommage du PC et Changement d'adresse IP"
'Lire les informations a propos du nom du PC et les adresses ip
Msgbox IP_Info,VbInformation,"Configuration réseau de l'ordinateur"
'*******************************************************************************
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
' ******************** Paramأ¨tres أ saisir au clavier ************************
strNouveauNom = Inputbox ("Entrer le nouveau nom du PC : ",Titre,"Hackoo-PC")
If strNouveauNom = "" Then Wscript.Quit()
' ***************************Changer le nom du PC ******************************
Set colComputers = objWMIService.ExecQuery ("Select * from Win32_ComputerSystem")
For Each objComputer in colComputers
err = objComputer.Rename(strNouveauNom)
Next
'*************************** Changer la description **********************************
strDescription = Inputbox("Enter Description : ",Titre,"Ordinateur de bureau balablalaaaa")
If strDescription = "" Then Wscript.Quit()
Set Obj= GetObject("winmgmts:\\" & strComputer).InstancesOf("Win32_OperatingSystem")
For Each x In Obj
x.Description = strDescription
x.Put_
Next
'***************************** Changement adresse IP **************************
Set colNetAdapters = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
Do
strIPAddress =Inputbox ("Entrer l'adresse IP : ",Titre,"192.168.1.150")
If strIPAddress = "" Then Wscript.Quit()
If IP_Valide(strIPAddress) = False Then
MsgBox "l'adresse ip " & strIPAddress & " est invalide !",vbCritical,Titre
End If
Loop until IP_Valide(strIPAddress) = True
Do
strSubnetMask = Inputbox ("Entrer le masque de sous réseau : ",Titre,"255.255.255.0")
If strSubnetMask = "" Then Wscript.Quit()
If IP_Valide(strSubnetMask) = False Then
MsgBox "l'adresse ip " & strSubnetMask & " est invalide !",vbCritical,Titre
End If
Loop Until IP_Valide(strSubnetMask) = True
Do
strGateway = Inputbox ("Entrer la passerelle : ",Titre,"192.168.1.1")
If strGateway = "" Then Wscript.Quit()
If IP_Valide(strGateway) = False Then
MsgBox "l'adresse ip " & strGateway & " est invalide !",vbCritical,Titre
End If
Loop Until IP_Valide(strSubnetMask) = True
Do
strDNSServers = Inputbox ("Entrer le DNS : ",Titre,"192.168.1.1")
If strDNSServers = "" Then Wscript.Quit()
If IP_Valide(strDNSServers) = False Then
MsgBox "l'adresse ip " & strDNSServers & " est invalide !",vbCritical,Titre
End If
Loop Until IP_Valide(strDNSServers) = True
strIPAddress = Array(strIPAddress)
strSubnetMask = Array(strSubnetMask)
strGateway = Array(strGateway)
strDNSServers = Array(strDNSServers)
strGatewayMetric = Array(1)
For Each objNetAdapter in colNetAdapters
errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
errGateways = objNetAdapter.SetGateways(strGateway,strGatewaymetric)
errDOM = objNetAdapter.SetDNSServerSearchOrder(strDNSServers)
If errEnable = 0 Then
MsgBox "The IP address has been changed.",vbInformation,Titre
'Lire les informations a propos du nom du PC et les adresses ip attribués
Msgbox IP_Info,VbInformation,"Configuration réseau de l'ordinateur"
Call Ask4Reboot()
Else
Msgbox "The IP address could not be changed.",vbCritical,Titre
Msgbox IP_Info,VbInformation,"Configuration réseau de l'ordinateur"
End If
Next
'*************************************************************************************
Function IP_Valide(ip)
Set RegularExpressionObject = New RegExp
With RegularExpressionObject
.Pattern = "^((25[0-5]|2[0-4]\d|1?\d?\d)\.){3}(25[0-5]|2[0-4]\d|1?\d?\d)$"
.IgnoreCase = False
If .Test(ip)= True then
IP_Valide = True
end if
End With
End Function
'*************************************************************************************
Function IP_Info()
Dim ComputerName,IPConfigSet,IPConfig,BailObtenu,BailExpirant
ComputerName="."
On error resume next
set IPConfigSet = GetObject("winmgmts:{impersonationLevel=impersonate}!//" & ComputerName).ExecQuery _
("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled=TRUE")
If Err.Number <> 0 Then
msgbox " - non accessible -"
Else
for each IPConfig in IPConfigSet
BailObtenu = IPConfig.DHCPLeaseObtained
BailExpirant = IPConfig.DHCPLeaseExpires
'---- Convertion des date et heure d'obtention et d'expiration des baux DHCP en un format lisible par l'utilisateur. ----
BailObtenu = mid(BailObtenu, 7, 2) & "/" & mid(BailObtenu, 5, 2) & "/" & mid(BailObtenu, 1, 4) & " - " & mid(BailObtenu, 9, 2)& ":" & mid(BailObtenu, 11, 2)& ":" & mid(BailObtenu, 13, 2)
BailExpirant = mid(BailExpirant, 7, 2) & "/" & mid(BailExpirant, 5, 2) & "/" & mid(BailExpirant, 1, 4) & " - " & mid(BailExpirant, 9, 2)& ":" & mid(BailExpirant, 11, 2)& ":" & mid(BailExpirant, 13, 2)
Msg = "Configuration réseau de l'ordinateur : " & IPConfig.DNSHostName & vbcrlf & vbcrlf & _
"Nom Machine " & vbtab & " : " & vbtab & IPConfig.DNSHostName & vbcrlf & vbcrlf & _
"Carte active" & vbtab & " : " & vbtab & IPConfig.Description & vbcrlf & vbcrlf & _
"Adresse MAC " & vbtab & " : " & vbtab & IPConfig.MACAddress & vbcrlf & _
"DHCP Activé" & vbtab & " : " & vbtab & IPConfig.DHCPEnabled & vbcrlf & vbcrlf & _
"Adresse IP " & vbtab & " : " & vbtab & IPConfig.IPAddress(0) & vbcrlf & _
"Masque " & vbtab & vbtab & " : " & vbtab & IPConfig.IPSubnet(0) & vbcrlf & _
"Passerelle " & vbtab & " : " & vbtab & IPConfig.DefaultIPGateway(0) & vbcrlf & _
"Serveur DHCP " & vbtab & " : " & vbtab & IPConfig.DHCPServer & vbcrlf & vbcrlf & _
"Serveur DNS " & vbtab & " : " & vbtab & IPConfig.DNSServerSearchOrder(0) & vbcrlf & _
" " & vbtab & vbtab & " : " & vbtab & IPConfig.DNSServerSearchOrder(1) & vbcrlf & _
vbcrlf & _
" Bail obtenu " & vbtab & " : " & vbtab & BailObtenu & vbcrlf & _
" Bail expirant " & vbtab & " : " & vbtab & BailExpirant
'"Serveur WINS " & vbtab & " : " & IPConfig.WINSPrimaryServer(0) & vbcrlf & _
'" " & vbtab & vbtab & " : " & IPConfig.WINSSecondaryServer(0)
'MsgBox Msg,VbInformation,"Configuration réseau de l'ordinateur "
Next
IP_Info = Msg
End If
End Function
'****************************************************************************
Function SimpleQuote(Str)
SimpleQuote = ChrW(39) & Str & ChrW(39)
End Function
'****************************************************************************
Sub Ask4Reboot()
Question = MsgBox("Le nom du PC changera en " & DblQuote(strNouveauNom) & " après le redémarrage de cet ordinateur" & vbCrLf &_
"Oui pour redémarrer" & vbCrLF &_
"Non pour annuler le redémarrage" & vbtab & "?",VbYesNo+VbQuestion,"Renommage du PC")
If Question = VbYes then
Reboot()
Else
wscript.Quit(1)
End If
End Sub
'***************************************************************************
Function DblQuote(Str)
DblQuote = chr(34) & Str & chr(34)
End function
'***************************************************************************
Sub Reboot()
Dim ws,Command,Result
Set ws = CreateObject("Wscript.Shell")
Command = "Shutdown.exe /r /t 20 /c "& DblQuote("Enregistrer vos documents - Redemarrage du PC dans 20 secondes")
Result = ws.run(Command,0,True)
End Sub
'************************************** |
Partager