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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
| Const ForReading = 1, ForWriting = 2, ForAppend = 8
'On Error Resume Next
' Script d'ouverture de session
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' INFORMATIONS GENERALES
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Date et heure
Dim varnow, Current, Vardate
Varnow = now
Current = TimeHHMMSS()
Vardate = Day(varnow) & "-" & Month(varnow) & "-" & Year(varnow) & "_at_" & Current
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' COLLECTE DES INFORMATIONS SYSTEMES / MACHINE / UTILISATEURS / SESSION-PROFIL
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim objShell,WshNetwork,objFSO,objTextFile
Dim UserPath,UserUpn,StrComputer,LocalFile,NetPath,OutFile,VarIP
'Const ForWriting = 2
Const OverwriteExisting = True
StrComputer="."
' Creation du fichier de log local, collecte des informations de session et de profil
Set WshShell = CreateObject("wscript.shell")
Set objShell = CreateObject("wscript.shell")
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set objFSO = CreateObject("scripting.filesystemobject")
UserPath = WshShell.ExpandEnvironmentStrings("%userprofile%") & "\session_log"
UserUpn = WshNetwork.UserName
LocalFile = UserPath & "\" & Vardate & "_.log"
'NetPath = "\\S-FR-DC01\LogIn$\"
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem",,48)
For Each objItem in colItems
Nom = objItem.Caption
Next
NetPath = "C:\Tmp\"
' OutFile = NetPath & Nom & "_" & UserUpn & "__" & VarIP & "__date-" & Vardate & "_.log"
If objFSO.FolderExists(UserPath) = False Then
objFSO.CreateFolder(UserPath)
End If
Set objTextFile = objFSO.CreateTextFile(LocalFile, True)
'Os info et CPU Name
Dim Reg_1, Reg_2, Reg_3, Reg_4, Reg_5, Reg_Bool
Reg_1 = "HKLM\Software\Microsoft\Windows NT\CurrentVersion\" & "ProductName"
Reg_2 = "HKLM\Software\Microsoft\Windows NT\CurrentVersion\" & "CSDVersion"
Reg_3 = "HKLM\Software\Microsoft\Windows NT\CurrentVersion\" & "CurrentVersion"
Reg_4 = "HKLM\Hardware\Description\System\CentralProcessor\0\" & "ProcessorNameString"
Reg_5 = "HKLM\SOFTWARE\Wow6432Node"
If RegValueExists(Reg_5) then
Reg_Bool = "x64"
OsType = WshShell.RegRead (Reg_1) & "__" & WshShell.RegRead (Reg_2) & "__" & WshShell.RegRead (Reg_3) & "__" & Reg_Bool
Elseif RegValueExists(Reg_5)= False then
Reg_Bool = "x86"
OsType = WshShell.RegRead (Reg_1) & "__" & WshShell.RegRead (Reg_2) & "__" & WshShell.RegRead (Reg_3) & "__" & Reg_Bool
End if
'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
OutFile = NetPath & Nom & "_" & UserUpn & "_" & VarIP & "_date-" & Vardate & "_.log"
' ECRITURE DES RESULTATS DE REQUETTE DANS LE FICHIER DE LOG
objTextFile.WriteLine "Computer : " & strComputer
objTextFile.WriteLine "OS : " & OsType
objTextFile.WriteLine "CPU : " & WshShell.RegRead (Reg_4)
objTextFile.WriteLine ProfilState()
objTextFile.WriteLine "Username : " & UserUpn
objTextFile.WriteLine "Adresse IP : " & varIP
objTextFile.WriteBlankLines (3)
' Récupération du RSOP si la machine execute un OS client
Dim ColSys,OSVersion
Set ColSys = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
For Each OS In ColSys
OSVersion = Left(OS.Version,3)
If InStr(OS.Caption, "Server") Then
objTextFile.Close
Exit For
Else
objTextFile.WriteLine "RSOP return"
objTextFile.Close
End if
Select Case OSVersion
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 , 0 '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_UserAccount",,48)
'On Error Resume Next
For Each Info in ColProfil
MySidUser = Info.SID
Next
KeyProfileStatus = WshShell.RegRead("HKLM\Software\Microsoft\Windows NT\CurrentVersion\ProfileList\" & MySidUser & "\State")
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 |
Partager