[Vbscript] :'Function' attendu (à la dernière ligne)

Orwell1984 Messages postés 2 Date d'inscription   Statut Membre Dernière intervention   -  
Orwell1984 Messages postés 2 Date d'inscription   Statut Membre Dernière intervention   -
Bonjour,

Je but sur un problème avec un script vbs que j'ai fait à l'aide de fonctions récupérées un peu partout.

Lorsque je l'exécute le "compilateur vbscript" me renvoit une erreur à la dernière ligne disant Fonction attendu.

Je vous remercie de votre aide.

Voici mon code:


'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

2 réponses

tuxboy Messages postés 995 Date d'inscription   Statut Membre Dernière intervention   190
 
Bonjour, au tout début,
'On Error Resume Next
Supprime le premier caractère...
0
Orwell1984 Messages postés 2 Date d'inscription   Statut Membre Dernière intervention  
 
Bonjour Tuxboy,

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.
0