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
|
Option Explicit
Const ForReading = 1
Dim objFSO, objFichierEntree, objFichierSortie
Dim strSeparateur, strLigne, strSection
Dim arrMachine
Dim intColHost, intColName, intColMac, intId, intR
Dim boolIni
If WScript.Arguments.Count = 0 Or WScript.Arguments.Count > 1 then
Msgbox "Paramètre manquant : faire glisser un et un seul fichier à traiter sur le script.", vbExclamation, WScript.ScriptName
WScript.Quit
End If
boolIni = (Right(LCase(WScript.Arguments(0)), 4) = ".ini")
If boolIni = True Then
strSeparateur = "|"
intColHost = 1
intColName = 0
intColMac = 4
Else
strSeparateur = vbTab
intR = Msgbox("S'agit-il d'un export de Dipiscan (oui) ou d'IPScan32 (non), ou ni l'un ni l'autre (annuler)", vbQuestion or vbYesNoCancel, WScript.ScriptName)
Select Case intR
Case vbYes:
intColHost = 0
intColName = 2
intColMac = 6
Case vbNo:
intColHost = 0
intColName = 1
intColMac = 5
Case Else:
Msgbox "Format non supporté", vbExclamation, WScript.ScriptName
WScript.Quit
End Select
End If
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFichierEntree = objFSO.OpenTextFile(WScript.Arguments(0), ForReading)
Set objFichierSortie = objFSO.CreateTextFile(WScript.Arguments(0) & ".xml")
Call Ecris("<?xml version=""1.0""?>\r\n", null)
Call Ecris("<!DOCTYPE italc-config-file>\r\n", null)
Call Ecris("<globalclientconfig version=""2.0.2"">\r\n", null)
Call Ecris("\t<body>\r\n", null)
intId = 1
While not(objFichierEntree.AtEndOfStream)
strLigne = Trim(objFichierEntree.ReadLine)
If boolIni = True Then
If Left(strLigne, 1) = "[" And Right(strLigne, 1) = "]" And LCase(strLigne) <> "[config]" Then
If strSection <> "" Then
Call Ecris("\t\t</classroom>\r\n", null)
End If
strSection = Replace(Replace(Trim(strLigne), "[", ""), "]", "")
Call Ecris("\t\t<classroom name=""%v"">\r\n", Array(strSection))
ElseIf strSection <> "" And Left(strLigne, 7) = "Machine" Then
arrMachine = Split(Split(Trim(strLigne), "=")(1), strSeparateur)
Call Ecris("\t\t\t<client hostname=""%v"" mac=""%v"" type=""0"" id=""%v"" name=""%v""/>\r\n", Array(arrMachine(intColHost), Replace(arrMachine(intColMac), "-", ":"), intId, arrMachine(intColName)))
intId = intId + 1
End If
Else
If strSection = "" Then
strSection = Mid(WScript.Arguments(0), Instr(WScript.Arguments(0), "\") + 1)
Call Ecris("\t\t<classroom name=""%v"">\r\n", Array(strSection))
ElseIf Left(strLigne, 1) <> "[" Then
arrMachine = Split(Trim(strLigne), strSeparateur)
Call Ecris("\t\t\t<client hostname=""%v"" mac=""%v"" type=""0"" id=""%v"" name=""%v""/>\r\n", Array(arrMachine(intColHost), Replace(arrMachine(intColMac), "-", ":"), intId, arrMachine(intColName)))
intId = intId + 1
End If
End If
Wend
Call Ecris("\t\t</classroom>\r\n", null)
Call Ecris("\t</body>\r\n", null)
Call Ecris("</globalclientconfig>\r\n", null)
objFichierSortie.Close
objFichierEntree.Close
Msgbox "Traitement terminé.", vbInformation, Wscript.ScriptName
WScript.Quit
Sub Ecris(byval chaine, byval valeurs)
Dim p, i
p = Instr(chaine, "%v")
i = 0
While p > 0
chaine = Left(chaine, p - 1) & valeurs(i) & Mid(chaine, p + 2)
p = Instr(chaine, "%v")
i = i + 1
Wend
chaine = Replace(chaine, "\t", vbTab)
chaine = Replace(chaine, "\r", vbCr)
chaine = Replace(chaine, "\n", vbLf)
objFichierSortie.Write(chaine)
End Sub |
Partager