'********************************************************************************************'
' VBScript
' Auteur : Timothy Borer & Jonas Caillet
' Date : 20.11.08
' Objectif : Rechecher version IE7 et modification de RunOnce_ & Rechecher activation NetBIOS
'********************************************************************************************'
'Option Explicit
On Error Resume Next
'Constantes
Const Log_Suivi = "G:\_Echange\Borer Timothy\Log_Suivi_PC.csv"
Const Log_Info = "G:\_Echange\Borer Timothy\Log_Info_PC.csv"
Const DossierNovel = "C:\NOVELL"
Const FichierGW = "C:\NOVELL\GroupWise\grpwise.exe"
'Variables
Dim WshNetwork, NomPc, objNet,strComputer, objWMIService, colOSes, objOS, sSP, colItems, objItem, dDate, sTime
Dim IPConfigSet, IPConfig, i, cIP, objFSO, colDrives, sTailleLibreC, sTailleTotalC, sTaillePC, Fcsv, colNetCards
Dim NetBIOS, objNetCard, bKeyHS1, bKeyCp2
'*******************************************************************************************************************
'### Phase 1
'### Recherche des informations system
'*** Trouver le nom du poste
Set WshNetwork = WScript.CreateObject("WScript.Network")
cNomPc = WshNetwork.ComputerName
'*** Recherche username
Set objNet = CreateObject("WScript.NetWork")
'*** Rechercher la version du service packl
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colOSes = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
For Each objOS In colOSes
sSP = objOS.ServicePackMajorVersion & "." & _
objOS.ServicePackMinorVersion
Next
'*** Recherche de la date et l'heure
Set colItems = objWMIService.ExecQuery("Select * from Win32_LocalTime",,48)
For Each objItem in colItems
dDate = objItem.Day & "/" & objItem.Month & "/" & objItem.Year
sTime = objItem.Hour & ":" & objItem.Minute
Next
'*** Recherche IP du poste
Set IPConfigSet = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery _
("select IPAddress from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE and DNSDomain=""JU.ch""")
For each IPConfig in IPConfigSet
If Not IsNull(IPConfig.IPAddress) then
For i=LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress)
'Donne à la variable cIP la valeur de l'IP du pc
cIP = IPConfig.IPAddress(i)
Next
End If
Next
'*** Recherche taille du poste
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set colDrives = objFSO.Drives
For Each objDrive in colDrives
If objDrive.DriveLetter = "C" then
sTailleLibreC = ((((objDrive.FreeSpace / 1024)/1024)/1024))
sTailleTotalC = (((objDrive.TotalSize / 1024)/1024)/1024)
sTaillePC = Left(((100 / sTailleTotalC) * sTailleLibreC),4)
End if
Next
'*******************************************************************************************************************
'### Phase 2
'### Créer trace info_pc.CSV
Set FSO = CreateObject("Scripting.FileSystemObject")
If Not (fso.FileExists(Log_Info)) Then
'On créer le fichier texte
Set Fcsv = FSO.CreateTextFile(Log_Info,2)
Set Fcsv = FSO.OpenTextFile(Log_Info,8)
'Titre
Fcsv.Write "Date" &";"& "NomPoste" &";"& "NomUser" &";"& "SP" &";"& "IP" &";"& "Taille_C_Total" &";"& "Taille_C_Libre" &";"& "Taille_%" & VbCrLf
' Date - Nom post - Nom user - SP - IP - TailleC -TailleCDispo - %
Fcsv.Close
End If
Set Fcsv = FSO.OpenTextFile(Log_Info,8)
Fcsv.Write dDate &" "& sTime &";"& cNomPc &";"& objNet.UserName &";"& sSP &";"& cIP &";"& Round(sTailleTotalC, 2) &";"& Round(sTailleLibreC, 3) &";"& sTaillePC & vbCrLf
Fcsv.Close
'*******************************************************************************************************************
'### PHASE 3
'### Créer trace suivi_pc.CSV
If Not (fso.FileExists(Log_Suivi)) Then
'On créer le fichier texte
Set Fcsv = FSO.CreateTextFile(Log_Suivi,2)
Set Fcsv = FSO.OpenTextFile(Log_Suivi,8)
Fcsv.Write "Date" &";"& "NomPoste" &";"& "NomUser" &";"& "SP" &";"& "IP" &";"& "Objet" &";"& "Version" & vbCrLf
Fcsv.Close
End If
'*******************************************************************************************************************
'### Phase 4
'### Execution du script en administrateur
Const WbemAuthenticationLevelPktPrivacy = 6
strUser = "pch_adm"
strPassword = "admin2000"
Set objWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = objwbemLocator.ConnectServer _
(cNomPc, root\cimv2, strUser, strPassword)
objWMIService.Security_.authenticationLevel = WbemAuthenticationLevelPktPrivacy
'Set colItems = objWMIService.ExecQuery _
'("Select * From Win32_OperatingSystem")
'For Each objItem in ColItems
' Wscript.Echo strComputer & ": " & objItem.Caption
'Next
'*******************************************************************************************************************
'### Phase 5
'### Modification NetBios, IE & GW ***
'**** Regarder si le netbios est activé sinon activation
Set colNetCards = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objNetCard in colNetCards
NetBIOS = objNetCard.TcpipNetbiosOptions
If Not(NetBIOS = 1) Then
objNetCard.SetTCPIPNetBIOS(1)
Set Fcsv = FSO.OpenTextFile(Log_Suivi,8)
'*** AJOUTE LE TRACE : NET BIOS
Fcsv.Write dDate &" "& sTime &";"& cNomPc &";"& objNet.UserName &";"& sSP &";"& cIP &";"& "Activation NetBIOS" & vbCrLf
Fcsv.Close
End If
Next
'*** Regarder la version d'internet explorer
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2\Applications\MicrosoftIE")
Set colIESettings = objWMIService.ExecQuery _
("Select * from MicrosoftIE_Summary")
For Each strIESetting In colIESettings
IEVer = strIESetting.Version
Next
If Left(IEVer,1) = 7 Then
'*** Modifie RunOnce
Set WshShell = WScript.CreateObject("WScript.Shell")
With WScript.CreateObject("WScript.Shell")
bKeyHS1 = WshShell.RegRead("HKCU\Software\Microsoft\Internet Explorer\Main\RunOnceHasShown")
bKeyCp2 = WshShell.RegRead("HKCU\Software\Microsoft\Internet Explorer\Main\RunOnceComplete")
If bKey1 = 0 And bKeyCp2 = 0 Then
.RegWrite "HKCU\Software\Microsoft\Internet Explorer\Main\RunOnceHasShown", 1, "REG_DWORD"
.RegWrite "HKCU\Software\Microsoft\Internet Explorer\Main\RunOnceComplete", 1, "REG_DWORD"
'*** AJOUTE TRACE : IE7
set Fcsv = FSO.OpenTextFile(Log_Suivi,8)
Fcsv.Write dDate &" "& sTime &";"& cNomPc &";"& objNet.UserName &";"& sSP &";"& cIP &";"& "RunOnce modifiés" &";"& "IE:V "& IEVer & VbCrLf
Fcsv.Close
End If
End With
End if
'*** Regarder la version de GroupeWise
If fso.FolderExists(DossierNovel) Then
GWVer = fso.GetFileVersion(FichierGW)
If GWVer <> "7.0.3.1068" then
'*** Ajoute trace : WGW
set Fcsv = FSO.OpenTextFile(Log_Suivi,8)
Fcsv.Write dDate &" "& sTime &";"& cNomPc &";"& objNet.UserName &";"& sSP &";"& cIP &";"& "GroupeWise" &";"& "GW:V " & GWVer & VbCrLf
Fcsv.Close
End If
End if
'### Termine
Le voilà :)
L'alcool c'est l'ennemi de tous, mais fuir son ennemi c'est lâche.