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
| ECRITURE DANS UN FICHIER
' Fichier = chemin vers le fichier (ex "c:\temp\exemple.txt")
' Contenu = chaîne de caractère à insérer dans le fichier
' Ajouter = True si l'on veut ajouter à la fin du fichier
' False si l'on veut écraser le fichier
Sub EcrireDansFichier(ByVal Fichier,ByVal Contenu,ByVal Ajouter)
Dim LeMode
Dim FsError
Dim LeFichierTexte
If Ajouter = True Then 'On ajoute le texte à la fin du fichier
LeMode=8
Else 'On ecrase le fichier pour ajouter notre texte
LeMode=2
End If
Set FsError = CreateObject("Scripting.FileSystemObject")
Set LeFichierTexte = FsError.OpenTextFile(Fichier,LeMode, True)
LeFichierTexte.Write Contenu
LeFichierTexte.Close
Set LeFichierTexte = Nothing
Set FsError = Nothing
End Sub
Dim sComputerName 'As string
Dim sWinMgmt 'As String
Dim SP
Dim sText 'As String
Dim tabul 'As Int
Dim args
tabul = -1
'Machine à interroger ...
'sComputerName = InputBox("Entrer le nom de l'ordinateur à interroger :",,"localhost")
Set args = WScript.Arguments
if args.Count=0 then
Wscript.quit
end if
sComputerName = args(0)
'wscript.echo "PC: " & sComputerName
'Repertoire où est situés le fichier de log de la machine
Dim objShell
Set objShell = WScript.CreateObject("WScript.Shell")
Dim cFolder
cFolder = "c:\TEMP\"
'On supprime le précédent s'il existe
'on inscript les informations de départ du script
Call EcrireDansFichier(cFolder & sComputerName & ".xml", _
"<?xml version=""1.0"" encoding=""ISO-8859-1""?>" & vbCrLf,False)
Call EcrireDansFichier(cFolder & sComputerName & ".xml", _
"<Scan Author='frstatech' Computer='" & sComputerName _
& "' date='" & cstr(Now()) _
& "'>" & vbCrLf,true)
'Chaine de Connexion à la ruche WMI
sWinMgmt = "winmgmts:{impersonationLevel=impersonate}!//" & sComputerName &""
'-------------------
'System
'-------------------
call DebutInfo("System",sText,tabul)
'Role
Dim objRole 'As WMI Object connecté à la ruche Win32_ComputerSystem
On Error Resume next
Set objRole = GetObject( sWinMgmt ).InstancesOf("Win32_ComputerSystem")
'si il y a une erreur, on supprime le fichier et on sort du programme
if err <> 0 then
kill "c:\TEMP\" & sComputerName & ".xml"
Wscript.quit
end if |
Partager