Set oFSO = CreateObject("Scripting.FileSystemObject") Set Shell = CreateObject("Wscript.Shell") Const TRISTATE_USE_DEFAULT = -2 Const TRISTATE_TRUE = -1 Const TRISTATE_FALSE = 0 Const OVERWRITE_TRUE = -1 Const OVERWRITE_FALSE = 0 Const LOCATION_MODIFY_TRUE = -1 Const LOCATION_MODIFY_FALSE = 0 Const TEXT_USE_DEFAULT = -2 Const TEXT_UNICODE = -1 'Open the file as Unicode. Const TEXT_ASCII = 0 'Open the file as ASCII. Dim TabUSB Redim TabUSB(0) If oFSO.FileExists(GetPath & "USMTExcludeDrives.xml") Then CodeRetour = oFSO.DeleteFile(GetPath & "USMTExcludeDrives.xml") StrComputerName = Shell.ExpandEnvironmentStrings("%COMPUTERNAME%") TraceLog GetPath & "USMTExcludeDrives.log", StrComputerName & " | " & "Start" 'Show drive letters associated with each ComputerName = "." Set wmiServices = GetObject ("winmgmts:{impersonationLevel=Impersonate}!//" & ComputerName) ' Get physical disk drive Set wmiDiskDrives = wmiServices.ExecQuery ( "SELECT Caption, DeviceID FROM Win32_DiskDrive WHERE InterfaceType = 'USB'") For Each wmiDiskDrive In wmiDiskDrives query = "ASSOCIATORS OF {Win32_DiskDrive.DeviceID='" & wmiDiskDrive.DeviceID & "'} WHERE AssocClass = Win32_DiskDriveToDiskPartition" Set wmiDiskPartitions = wmiServices.ExecQuery(query) For Each wmiDiskPartition In wmiDiskPartitions 'Use partition device id to find logical disk Set wmiLogicalDisks = wmiServices.ExecQuery ("ASSOCIATORS OF {Win32_DiskPartition.DeviceID='" & wmiDiskPartition.DeviceID & "'} WHERE AssocClass = Win32_LogicalDiskToPartition") x = "" For Each wmiLogicalDisk In wmiLogicalDisks TabUSB(Ubound(TabUSB)) = wmiLogicalDisk.DeviceID Redim preserve tabUSB(Ubound(TabUSB)+1) TraceLog GetPath & "USMTExcludeDrives.log", StrComputerName & " | " & "USB=" & wmiLogicalDisk.DeviceID Next Next Next If Ubound(TabUSB) > 0 Then Set oFile = oFSO.CreateTextFile(GetPath & "USMTExcludeDrives.xml", OVERWRITE_TRUE, TEXT_UNICODE) oFile.WriteLine "" oFile.WriteLine "" oFile.WriteLine "" oFile.WriteLine " <_locDefinition>" oFile.WriteLine " <_locDefault _loc=""locNone""/>" oFile.WriteLine " <_locTag _loc=""locData"">displayName" oFile.WriteLine " " oFile.WriteLine " " oFile.WriteLine " Unconditional Exclude Drives" oFile.WriteLine " " oFile.WriteLine " " oFile.WriteLine " " oFile.WriteLine " " ' H:\* [*] For i = 0 To (Ubound(TabUSB)-1) oFile.WriteLine " " & UCase(TabUSB(i)) & "\* [*]" Next oFile.WriteLine " " oFile.WriteLine " " oFile.WriteLine " " oFile.WriteLine " " oFile.WriteLine " " oFile.WriteLine "" oFile.Close TraceLog GetPath & "USMTExcludeDrives.log", StrComputerName & " | " & "Fin de creation du xml" Else TraceLog GetPath & "USMTExcludeDrives.log", StrComputerName & " | " & "Pas de disque USB" End If Function GetPath() Dim path path = WScript.ScriptFullName GetPath = Left(path, InStrRev(path, "\")) End Function Function TraceLog(FichierLog,Commentaire) Dim oFso, fich Set oFso = CreateObject("Scripting.FileSystemObject") Set fich = oFso.OpenTextFile(FichierLog,8,True) fich.writeline cstr(Date) & " " & cstr(Time) & " | " & Commentaire fich.close End Function