' ---------------------------------------------------------- ' Script donnant les caractéristiques des disques ' d'un ordinateur local ou distant ' Syntaxe: ' alldisks [/d] | [/m] ' Paramètres: ' : nom de domaine ou workgroup ' analyse de tous les ordinateurs ' du domaine ou workgroup ' Si absent, on prend le domaine ' de la machine locale ' : nom NetBIOS de la machine ' si absent : machine locale ' ' JC BELLAMY © 2002 ' ---------------------------------------------------------- typeD=Array("Inconnu","Amovible","Fixe","Réseau","CD-ROM","RAM Disk") Dim net, shell, computer, args, fso, WMISet,oWinnt Set net = Wscript.CreateObject("WScript.Network") Set shell = WScript.CreateObject("WScript.Shell") Set fso = WScript.CreateObject("Scripting.FileSystemObject") Set args = Wscript.Arguments nbargs=args.count TestHost true If testarg("?") or testarg("h") Then Syntaxe "" If testarg("d") Then domain=getarg("d") If domain="" Then Set ComputerSystem = GetObject("winmgmts:{impersonationLevel=impersonate}").InstancesOf("Win32_ComputerSystem") for each ComputerItem in ComputerSystem domain=ComputerItem.Domain next End If Wscript.echo "Analyse des disques des ordinateurs du domaine " & Ucase(Domain) Wscript.echo "-----------------------------------------------" & string(len(Domain),"-") set oWinnt=GetObject("WinNT://" & domain) For each oDomainItem in oWinnt classe=oDomainItem.Class Computer=oDomainItem.Name If classe="Computer" Then InfosDisques Computer Next else If testarg("m") then computer=getarg("m") else computer=net.ComputerName End If InfosDisques Computer End If wscript.quit '-------------------------------------------------------------------- Sub InfosDisques(computer) set WMISet = GetObject("winmgmts:{impersonationLevel=impersonate}!//" & Computer).ExecQuery _ ("SELECT * FROM Win32_LogicalDisk") wscript.echo "Liste des unités de disques sur " & ucase(computer) Message=VBCRLF Message=Message & " | " & FormatStrL("Nom",11) & " | " & FormatStrL("Type",8) Message=Message & " | " & FormatStrL("Système",8) Message=Message & " | " & FormatStrL(" Taille (Mo) ",17) Message=Message & " | " & FormatStrL(" %",3) Message=Message & " | " & FormatStrL("N°série",8) Message=Message & VBCRLF Message=Message & " | " & FormatStrL("",11) & " | " & FormatStrL("",8) Message=Message & " | " & FormatStrL("",8) Message=Message & " | " & FormatStrR("Maxi",7) & " | " & FormatStrR("Libre",7) Message=Message & " | " & FormatStrL("lib",3) Message=Message & " | " Message=Message & VBCRLF Message=Message & "---+-------------+----------+----------+---------+---------+-----+---------" Message=Message & VBCRLF CumulTotal=0 CumulAvail=0 Mega=1048576 For each Disk in WMISet Capa=Disk.Size Desc=TypeD(Disk.DriveType-1) If Capa<>"" Then Name=Disk.VolumeName Serial=Disk.VolumeSerialNumber TT=int(cdbl(Capa)/mega) TL=int(cdbl(Disk.FreeSpace)/mega) Syst=Disk.FileSystem If TT>0 Then pc=int(TL*100/TT) Else pc="" End If If Disk.DriveType=3 Then CumulTotal=CumulTotal+TT CumulAvail=CumulAvail+TL End If Else Name="" Serial="" TT="" TL="" Syst="non prêt" pc="" End If Message=Message & Disk.Name & " | " & FormatStrL(name,11) & " | " & FormatStrL(Desc,8) Message=Message & " | " & FormatStrL(syst,8) Message=Message & " | " & FormatStrR(TT,7) & " | " & FormatStrR(TL,7) Message=Message & " | " & FormatStrR(pc,3)& " | " & Serial Message=Message & VBCRLF Next Message=Message & "---+-------------+----------+----------+---------+---------+-----+---------" Message=Message & VBCRLF Message=Message & " | " & FormatStrL("TOTAL fixes",11) & " | " & FormatStrL("",8) Message=Message & " | " & FormatStrL("",8) Message=Message & " | " & FormatStrR(CumulTotal,7) & " | " & FormatStrR(CumulAvail,7) Message=Message & " | " & FormatStrR(int(CumulAvail*100/CumulTotal),3) Message=Message & " | " & VBCRLF wscript.echo Message End Sub '-------------------------------------------------------------------- 'Sous-programme de test du moteur 'Vu les sorties générées, c'est CSCRIPT (et non pas WSCRIPT) 'qui doit être utilisé de préférence Sub TestHost(force) dim rep strappli=lcase(Wscript.ScriptFullName) strFullName =lcase(WScript.FullName) i=InStr(1,strFullName,".exe",1) j=InStrRev(strFullName,"\",i,1) strCommand=Mid(strFullName,j+1,i-j-1) if strCommand<>"cscript" then If force then Init="Ce script doit être lancé avec CSCRIPT" Else Init="Il est préférable de lancer ce script avec CSCRIPT" End If rep=MsgBox(Init & VBCRLF & _ "Cela peut être rendu permanent avec la commande" & VBCRLF & _ "cscript //H:CScript //S /Nologo" & VBCRLF & _ "Voulez-vous que ce soit fait automatiquement?", _ vbYesNo + vbQuestion,strappli) if rep=vbYes then nomcmd="setscript.bat" Set ficcmd = fso.CreateTextFile(nomcmd) ficcmd.writeline "@echo off" ficcmd.writeline "cscript //H:CScript //S /Nologo" ficcmd.writeline "pause" params="" For i = 0 To nbargs-1 params=params & " " & args(i) next ficcmd.writeline chr(34) & strappli & chr(34) & params ficcmd.writeline "pause" ficcmd.close shell.Run nomcmd, SW_SHOWNORMAL,true force=true end if If force then WScript.Quit end if end sub '-------------------------------------------------------------------- Function FormatStrL(ch,lmax) l=len(ch) If l] | [/m]" & VBCRLF msg=msg & " alldisks [-d] | [-m]" & VBCRLF msg=msg & " : nom de domaine ou workgroup" & VBCRLF msg=msg & " analyse de tous les ordinateurs" & VBCRLF msg=msg & " domaine ou workgroup" & VBCRLF msg=msg & " Si absent, on prend le domaine" & VBCRLF msg=msg & " de la machine locale" & VBCRLF msg=msg & " : nom NetBIOS de la machine" & VBCRLF msg=msg & " si absent : machine locale" & VBCRLF msg=msg & "Exemples : " & VBCRLF msg=msg & " alldisks " & VBCRLF msg=msg & " analyse les disques de la machine locale" & VBCRLF msg=msg & " alldisks /d" & VBCRLF msg=msg & " analyse les disques de toutes les machines" & VBCRLF msg=msg & " du domaine de la machine locale" & VBCRLF msg=msg & " alldisks /dMAPLENET" & VBCRLF msg=msg & " analyse les disques de toutes les machines" & VBCRLF msg=msg & " du domaine ""MAPLENET""" & VBCRLF msg=msg & " alldisks /mBINGERVILLE" & VBCRLF msg=msg & " analyse les disques de la machine distante ""BINGERVILLE""" & VBCRLF & VBCRLF wscript.echo msg wscript.quit End Sub '-------------------------------------------------------------------- Function testarg(param) testarg=false For i = 0 To nbargs-1 curarg=lcase(args(i)) If left(curarg,1)="/" or left(curarg,1)="-" Then If mid(curarg,2,len(param))=param Then testarg=true exit function End If End If Next End Function '-------------------------------------------------------------------- Function getarg(param) getarg="" For i = 0 To nbargs-1 curarg=lcase(args(i)) If left(curarg,1)="/" or left(curarg,1)="-" Then If mid(curarg,2,len(param))=param Then getarg=mid(args(i),2+len(param)) exit function End If End If Next End Function '--------------------------------------------------------------------