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 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
|
'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
Const ForAppend = 8
StrComputer="."
' 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")
UserPath = WshShell.ExpandEnvironmentStrings("%userprofile%") & "\session_log"
UserUpn = WshNetwork.UserName
LocalFile = UserPath & "\" & Vardate & "_.log"
NetPath = "\\S-FR-DC01\LogIn$\"
OutFile = NetPath & StrComputer & "_" & 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
Else if RegKeyExists(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
' 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 , 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")
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