'Exemple d'utilisation Wscript.echo SIDBrutToSIDString("010500000000000515000000B93E0E19C1406A2E0363450075060000") Public Function SIDBrutToSIDString(ByVal MonSID) 'Version du 20 fevrier 2007 'Convertit un SID qui est en format brut en un SID sous forme S-1-5-21 etc .... 'Exemple : '010500000000000515000000B93E0E19C1406A2E0363450075060000 'Devient 'S-1-5-15-420363961-778715329-4547331-1653 'Realise avec l'aide des explications trouvées sur 'http://blogs.msdn.com/oldnewthing/archive/2004/03/15/89753.aspx 'Signification des chiffres 'S-1- version number (SID_REVISION) '-5- SECURITY_NT_AUTHORITY '-21- SECURITY_NT_NON_UNIQUE '-...-...-...- these identify the machine that issued the SID '72713 unique user id on the machine Dim MonResultat Dim NombreDeMoins Dim ChiffreTempo SIDBrutToSIDString = MonSID MonSID = Trim(MonSID) If Len(MonSID) > 0 Then MonResultat = "S-" 'Extraction du premier chiffre MonResultat = MonResultat & CLng(Left(MonSID, 2)) MonSID = Mid(MonSID, 3) 'Extraction du nombre de - NombreDeMoins = CLng(Left(MonSID, 2)) MonSID = Mid(MonSID, 3) 'Extraction de 12 MonResultat = MonResultat & "-" & CLng(Left(MonSID, 12)) MonSID = Mid(MonSID, 13) 'Extraction de 8 ChiffreTempo = Left(MonSID, 8) ChiffreTempo = PermutterPourSID(ChiffreTempo) ChiffreTempo = Hexa2Decimal(ChiffreTempo) 'ChiffreTempo = CDec("&H" & ChiffreTempo) MonSID = Mid(MonSID, 9) MonResultat = MonResultat & "-" & ChiffreTempo For Compteur = 1 To NombreDeMoins If Len(MonSID) = 0 Then Exit For End If 'Extraction de 8 ChiffreTempo = Left(MonSID, 8) ChiffreTempo = PermutterPourSID(ChiffreTempo) ChiffreTempo = Hexa2Decimal(ChiffreTempo) 'ChiffreTempo = CDec("&H" & ChiffreTempo) MonSID = Mid(MonSID, 9) MonResultat = MonResultat & "-" & ChiffreTempo Next SIDBrutToSIDString = MonResultat End If 'If Len(MonSID) > 0 Then End Function Public Function PermutterPourSID(ByVal Meschiffres) 'Version du 30 nov 2006 'Inverse les lettres par paire de 2 Dim LeResultat PermutterPourSID = Meschiffres LeResultat = "" If Len(Meschiffres) > 0 Then Do While Len(Meschiffres) > 1 LeResultat = Left(Meschiffres, 2) & LeResultat If Len(Meschiffres) >= 2 Then Meschiffres = Mid(Meschiffres, 3) End If Loop If Len(Meschiffres) = 1 Then LeResultat = Meschiffres & LeResultat End If PermutterPourSID = LeResultat End If End Function Public Function Hexa2Decimal(ByVal MonHexa) 'Version du 05 décembre 2006 'On rentre un hexadécimal et on ressort un décimal Dim Compteur Dim UnChiffreHexa Dim UnChiffreDecimal Dim ChiffreAAjouter Dim Total Dim Puissance Hexa2Decimal = "" 'Par défaut Total = 0 Puissance = 0 For Compteur = Len(MonHexa) To 1 Step -1 UnChiffreHexa = Mid(MonHexa, Compteur, 1) 'On convertit le chiffre Hexa en chiffre décimal Select Case LCase(UnChiffreHexa) Case "f" UnChiffreDecimal = 15 Case "e" UnChiffreDecimal = 14 Case "d" UnChiffreDecimal = 13 Case "c" UnChiffreDecimal = 12 Case "b" UnChiffreDecimal = 11 Case "a" UnChiffreDecimal = 10 Case Else UnChiffreDecimal = CInt(UnChiffreHexa) End Select ChiffreAAjouter = UnChiffreDecimal * (16 ^ Puissance) Puissance = Puissance + 1 Total = Total + ChiffreAAjouter Next Hexa2Decimal = Total End Function