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
| Sub Lancement()
Dim Processus As New ProcessStartInfo("C:\..\cmd.exe")
Process.Start(Processus)
'Création de la base de données et remplissage de celle-ci à partir du résultat de la commande
'en utilisant le stream StreamReader après formatage
Dim StreamRead As StreamReader = File.OpenText("C:\..\configuraton.txt")
Dim Contenu1, Contenu2, Contenu3 As String
'On parcourt chaque ligne et on en fait ce qu'on veut. Dans notre cas, on l'ajoute dans notre base de
'données qu'il faudra vider une fois l'opération de traitement terminées.
Do Until StreamRead.Peek = -1
'Lecture de la ligne dans le fichier configuration et découpage des lignes pour l'affectation dans
'la base de données. Pour cela une première boucle for qui va tout d'abord récupérer le nom de la
'machine et ensuite en fonction une nouvelle boucle va se faire pour pouvoir récupérer l'adresse
'ip et l'adresse mac. Enfin la dernière boucle sera pour le type de boot
Contenu1 = StreamRead.ReadLine
Contenu2 = StreamRead.ReadLine
Contenu3 = StreamRead.ReadLine
Dim nomP, nomA, nomR As String
Dim ipP, ipA, ipR As String
Dim macP, macA, macR As String
Dim bootp, boota, bootr As String
Dim tmpnom, tmpipmac, tmpboot As String()
tmpnom = Contenu2.Split(" ")
For i As Integer = 0 To tmpnom.Length - 1
Dim tempnom As String = tmpnom(i)
If (tempnom.StartsWith("PG")) Then
nomP = tempnom
tmpipmac = Contenu1.Split(" ")
For j As Integer = 0 To tmpipmac.Length - 1
Dim tampo As String = tmpipmac(i)
If (Not String.Equals(tampo, "193.50.231.0")) Then
ipP = tampo
End If
If (tampo.StartsWith("00") And tampo.Contains("00")) Then
macP = tampo
End If
Next
tmpboot = Contenu3.Split(" ")
For k As Integer = 0 To tmpboot.Length - 1
Dim tempboot = tmpboot(i)
If (tempboot.EndsWith("com") Or tempboot.EndsWith("com1")) Then
bootp = tempboot
End If
Next
ElseIf (tempnom.StartsWith("AG")) Then
nomA = tempnom
tmpipmac = Contenu1.Split(" ")
For j As Integer = 0 To tmpipmac.Length - 1
Dim tampo As String = tmpipmac(i)
If (Not String.Equals(tampo, "193.50.231.0")) Then
ipA = tampo
End If
If (tampo.StartsWith("00") And tampo.Contains("00")) Then
macA = tampo
End If
Next
tmpboot = Contenu3.Split(" ")
For k As Integer = 0 To tmpboot.Length - 1
Dim tempboot = tmpboot(i)
If (tempboot.EndsWith("com") Or tempboot.EndsWith("com1")) Then
boota = tempboot
End If
Next
ElseIf (tempnom.StartsWith("RG")) Then
nomR = tempnom
tmpipmac = Contenu1.Split(" ")
For j As Integer = 0 To tmpipmac.Length - 1
Dim tampo As String = tmpipmac(i)
If (Not String.Equals(tampo, "193.50.231.0")) Then
ipR = tampo
End If
If (tampo.StartsWith("00") And tampo.Contains("00")) Then
macR = tampo
End If
Next
tmpboot = Contenu3.Split(" ")
For k As Integer = 0 To tmpboot.Length - 1
Dim tempboot = tmpboot(i)
If (tempboot.EndsWith("com") Or tempboot.EndsWith("com1")) Then
bootr = tempboot
End If
Next
End If
Next
'Connexion à la base de données. On vérifie que la connexion est bien établi pour pouvoir
'insèrer les données obtenues dans le fichier configuration.txt
connexion.ConnectionString = "Data Source=localhost;Initial Catalog=base;Integrated Security=True"
connexion.Open()
If connexion.State = ConnectionState.Open Then
Dim requeteP As SqlCommand = New SqlCommand("Insert into machineP [(nomp)(adresseipp)(macp)(bootp)] values (nomP,ipP,macP,bootP)", connexion)
Dim requeteA As SqlCommand = New SqlCommand("Insert into machineA [(noma)(adresseipa)(maca)(boota)] values (nomP,ipP,macP,bootP)", connexion)
Dim requeteR As SqlCommand = New SqlCommand("Insert into machineR [(nomr)(adresseipr)(macr)(bootr)] values (nomP,ipP,macP,bootP)", connexion)
requeteP.ExecuteNonQuery()
requeteA.ExecuteNonQuery()
requeteR.ExecuteNonQuery()
End If
Loop
StreamRead.Close()
End Sub |
Partager