' Creation du fichier de log local, collecte des informations de session et de profil Set WshShell = CreateObject("wscript.shell") Set WshNetwork = WScript.CreateObject("WScript.Network") Set objFSO = CreateObject("scripting.filesystemobject")
'Collecte des informations de configuration IP du poste Dim objWMIService,IPItems Set objWMIService = GetObject("winmgmts:\\" & strcomputer & "\root\CIMV2") Set IPItems = objWMIService.ExecQuery("Select IPAddress from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
For Each IPConfig In IPItems If Not IsNull(IPConfig.IPAddress) Then For i=LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress) If varIP="" Then varIP=IPConfig.IPAddress(0) End If Next End If Next
' ECRITURE DES RESULTATS DE REQUETTE DANS LE FICHIER DE LOG
Case "5.0","5.1","5.2" objShell.Run "cmd.exe /c gpresult >>" & LocalFile
Case "6.0","6.1","6.2" objShell.Run "cmd.exe /c gpresult /R >>" & LocalFile
Case Else
objShell.Run "cmd /c echo impossible de détécter le système d'exploitation et donc de déterminer la syntaxe de gpresult >>" & LocalFile
End Select
Next
WScript.Sleep 3000
'Copie du fichier sur le share avec indication du nom d'ordinateur du login utilisateur et horodatage dans le nom du fichier objFSO.CopyFile LocalFile , Outfile , OverwriteExisting
' Vide le contenu du session_log antérieur à 60 jours Dim objLocalFolder,objFile,objSubfolder,objNetFolder Dim DayToKeep
DayToKeep = 60 Set objLocalFolder = objFSO.GetFolder(UserPath)
For Each objFile In objLocalFolder.files If DateDiff("d", objFile.DateCreated,Now) > DayToKeep Then objFile.Delete True objFile End If Next
For Each objSubfolder In objLocalFolder.Subfolders If DateDiff("d", objSubfolder.DateCreated,Now) > DayToKeep Then objSubfolder.Delete True End If Next
Set objNetFolder = objFSO.GetFolder(NetPath)
For Each objFile In objNetFolder.files If DateDiff("d", objFile.DateCreated,Now) > DayToKeep Then objFile.Delete True End If Next
For Each objSubfolder In objNetFolder.Subfolders If DateDiff("d", objSubfolder.DateCreated,Now) > DayToKeep Then objSubfolder.Delete True End If Next
'annulation / vidage des objets set objTextFile = Nothing set objFSO = Nothing Set objFile = Nothing Set objFolder = Nothing set WshShell = Nothing Set WshNetwork = Nothing Set objWMIService = Nothing Set objTextStream = Nothing Set objLocalFolder = Nothing Set objNetFolder = Nothing
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''' BLOC DE FONCTIONS ''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Fonction heure
Function TimeHHMMSS()
Dim retv, d d = Now retv = Right("00" & Hour(d), 2) & "-" & Right("00" & Minute(d), 2) & "-" & Right("00" & Second(d), 2) TimeHHMMSS = retv
End Function
' Fonction Reg TEST
Function RegValueExists(sRegValue) ' Returns True or False based of the existence of a registry value. Dim oShell, RegReadReturn Set oShell = CreateObject("WScript.Shell") RegValueExists = True ' init value On Error Resume Next RegReadReturn = oShell.RegRead(sRegValue) If Err.Number <> 0 Then RegValueExists = False End if On Error Goto 0 End Function
' Fonction profil status
Function ProfilState()
Dim oWMI,ColProfil,Info,KeyProfileStatus,MyUserSid,Etat
Set oWMI = GetObject("winmgmts:\\.\root\cimv2")
Set ColProfil = objWMIService.ExecQuery("Select * From Win32_UserProfile")
Select case KeyProfileStatus Case 0 Etat = "Le profil est de type : Normal" Case 16 Etat = "Le profil est de type : Itinérant" Case 20 Etat = "Le profil est de type : Itinérant" & Vbtab & "1er ouverture de Session - Profil local supprimé" Case 24 Etat = "Le profil est de type : Itinérant" & Vbtab & "Profil serveur supprimé" Case 262149 Etat = "Le profil est de type : Mandatory" & Vbtab & "1er ouverture de Session" Case 393217 Etat = "Le profil est de type : Mandatory" Case 516 Etat = "Le profil est de type : Normal" & Vbtab & "1er ouverture de Session" Case 540 Etat = "Le profil est de type : Itinérant" & Vbtab & "1er ouverture de Session" Case 2564 Etat = "Le profil est de type : Temporaire" Case Else Etat ="Le profil est de type : Inconnu"
End Select
ProfilState = Etat
End Function
A voir également:
[Vbscript] :'Function' attendu (à la dernière ligne)
Merci pour ta réponse.
Je viens de dé-commenter le On Error Resume Next mais j'ai encore une erreur à la dernière ligne.
Cette fois il dit End attendu.