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
| ' Initialize Objects
Dim LocalClass_StdRegProv: Set LocalClass_StdRegProv = GetObject("winmgmts:{impersonationlevel=impersonate}!//./root/default:StdRegProv")
Dim EmptyRecordset: Set EmptyRecordset = CreateObject("ADODB.Recordset")
' Define Constants
Const HKEY_CLASSES_ROOT = &H80000000, HKCR = &H80000000
Const HKEY_CURRENT_USER = &H80000001, HKCU = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002, HKLM = &H80000002
Const HKEY_USERS = &H80000003, HKU = &H80000003
Const HKEY_PERFORMANCE_DATA = &H80000004, HKPD = &H80000004
Const HKEY_CURRENT_CONFIG = &H80000005, HKCC = &H80000005
Const HKEY_DYN_DATA = &H80000006, HKDD = &H80000006
Const MaxCharacters = 255
Const adVarChar = 200
Const adInteger = 3
' Dimension Public Variables
Dim EntryNumber: EntryNumber = 0
Dim Return
EmptyRecordset.Fields.Append "Entry", adInteger
EmptyRecordset.Fields.Append "Name", adVarChar, MaxCharacters
EmptyRecordset.Fields.Append "Server", adVarChar, MaxCharacters
EmptyRecordset.Fields.Append "Port", adInteger
EmptyRecordset.Open
' Add server/port
EntryNumber = EntryNumber + 1
EmptyRecordset.AddNew
EmptyRecordset("Entry") = EntryNumber
EmptyRecordset("Name") = "Connexion au travail avec proxy"
EmptyRecordset("Server") = "172.16.0.1"
EmptyRecordset("Port") = "3128"
EmptyRecordset.Update
EntryNumber = EntryNumber + 1
EmptyRecordset.AddNew
EmptyRecordset("Entry") = EntryNumber
EmptyRecordset("Name") = "Connexion à la maison avec WIFI DHCP Activé"
EmptyRecordset("Server") = ""
EmptyRecordset("Port") = "80"
EmptyRecordset.Update
Dim Message
EmptyRecordset.MoveFirst
Do While EmptyRecordset.EOF = False
Message = Message & EmptyRecordset("Entry").Value & "-" & vbTab & EmptyRecordset("Name").Value & vbCrLf
EmptyRecordset.MoveNext
Loop
Do
Dim intAnswer: intAnswer = InputBox(Message, "Entrer 1 ou 2 puis valider par OK © Hackoo Crackoo","1")
If IsNumeric(intAnswer) = True Then intAnswer = CLng(intAnswer)
If intAnswer > EmptyRecordset.RecordCount Or intAnswer < 0 Then MsgBox "Invalide entrée, veuillez réessayer ...",16,"Invalide entrée, veuillez réessayer ..."
Loop Until (((VarType(intAnswer) And vbLong) = vbLong) And intAnswer <= EmptyRecordset.RecordCount And intAnswer >= 0)
Select Case True
Case (((VarType(intAnswer) And vbLong) = vbLong) And intAnswer = EmptyRecordset.RecordCount And intAnswer > 0)
DesactiverProxy()
ActiverDHCP()
Case (intAnswer = 0)
MsgBox "Annulé. Quitter.",48,"Annulé. Quitter."
Case (((VarType(intAnswer) And vbLong) = vbLong) And intAnswer <= EmptyRecordset.RecordCount And intAnswer > 0)
EmptyRecordset.Filter = "Entry=" & intAnswer
Dim ProxyServer: ProxyServer = EmptyRecordset("Server").Value & ":" & EmptyRecordset("Port").Value
intAnswer = MsgBox("Voulez-vous définir le proxy pour " & EmptyRecordset("Name").Value & " (" & ProxyServer & ") ?", vbQuestion + vbYesNo, "Confirmez-vous ?")
If intAnswer = vbYes Then
Return = LocalClass_StdRegProv.SetDWORDValue(HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Internet Settings","ProxyEnable",1)
Return = LocalClass_StdRegProv.SetStringValue(HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Internet Settings","ProxyServer",ProxyServer)
Call ChangeIP_Static()
If Err.Number = 0 And Return = 0 Then
MsgBox "Les paramètres de proxy sont modifiés. Quitter.",64,"Les paramètres de proxy sont modifiés. Quitter."
Else
MsgBox "Les paramètres de proxy ne changent pas. Quitter.",48,"Les paramètres proxy ne changent pas. Quitter."
End If
Else
MsgBox "Aucune modification apportée. Quitter.",48,"Aucune modification apportée. Quitter."
End If
Case Else
WScript.Echo "Entrée Invalide. Quitter",16,"Entrée Invalide. Quitter"
End Select
Sub ChangeIP_Static()
strIP = Array("172.16.0.100")
strmask = Array("255.255.255.0")
strGateway = Array("172.16.0.1")
strGatewayMetric = Array(1)
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colNetAdapters = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
For Each objNetAdapter in colNetAdapters
errEnable = objNetAdapter.EnableStatic(strIP, strmask)
errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
If errEnable = 0 Then
MsgBox "L'adresse IP a été changé.",64,"L'adresse IP a été changé."
Else
MsgBox "L'adresse IP ne peut pas être changé.",16,"L'adresse IP ne peut pas être changé."
End If
Next
End Sub
Sub DesactiverProxy()
Set ws = createObject("wscript.Shell")
ws.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable",0,"REG_DWORD"
End Sub
Sub ActiverDHCP()
Titre = "Connexion à la maison avec WIFI DHCP Activé"
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colNetAdapters = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
For Each objNetAdapter in colNetAdapters
errEnable = objNetAdapter.EnableDHCP()
errGateways = objNetAdapter.SetGateways()
If errEnable = 0 Then
MsgBox "L'adresse IP a été bien changé et le DHCP est désormais Activé !" & vbCrLf & Titre,64,Titre
Else
MsgBox "L'adresse IP n'a pas été changé !" ,16, "Changer IP"
End If
Next
End Sub |
Partager