Meilleur auteur de réponses
Erreur Windows Script Host - - L'entrée dépasse la fin du fichier

Question
-
Bonjour,
Lorsque mes utilisateurs ouvrent leur session sur leur poste, ils ont une erreur qui apparaît :
Voici le contenu du script :
' Logon5.vbs
' VBScript Logon script.
' This program demonstrates how to log information to a log file.
'
' ----------------------------------------------------------------------
' Copyright (c) 2003-2010 Richard L. Mueller
' Hilltop Lab web site - http://www.rlmueller.net
' Version 1 - March 26, 2003
' Version 1.1 - January 25, 2004 - Modify error trapping.
' Version 1.2 - June 10, 2010 - Delimit log file with ";".
' Version 1.3 - November 6, 2010 - No need to set objects to Nothing.
'
' You have a royalty-free right to use, modify, reproduce, and
' distribute this script file in any way you find useful, provided that
' you agree that the copyright owner above has no warranty, obligations,
' or liability for such use.
Option Explicit
Dim objFSO, objLogFile, objNetwork, objShell, strText, intAns
Dim intConstants, intTimeout, strTitle, intCount, blnLog
Dim strUserName, strComputerName, strIP, strShare, strLogFile
strShare = "\\CMMAS02\LogsConnexion"
strLogFile = "logUsagers_" & Year(Date) & "_" & Month(Date) & ".csv"
intTimeout = 20
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objNetwork = CreateObject("Wscript.Network")
Set objShell = CreateObject("Wscript.Shell")
strUserName = objNetwork.UserName
strComputerName = objNetwork.ComputerName
strIP = Join(GetIPAddresses())
' Log date/time, user name, computer name, and IP address.
If (objFSO.FolderExists(strShare) = True) Then
On Error Resume Next
Set objLogFile = objFSO.OpenTextFile(strShare & "\" _
& strLogFile, 8, True, 0)
If (Err.Number = 0) Then
' Make three attempts to write to log file.
intCount = 1
blnLog = False
Do Until intCount = 3
objLogFile.WriteLine "Logon;" & Now & ";" _
& strComputerName & ";" & strUserName & ";" & strIP
If (Err.Number = 0) Then
intCount = 3
blnLog = True
Else
Err.Clear
intCount = intCount + 1
If (Wscript.Version > 5) Then
Wscript.Sleep 200
End If
End If
Loop
On Error GoTo 0
If (blnLog = False) Then
strTitle = "Logon Error"
strText = "Log cannot be written."
strText = strText & vbCrlf _
& "Another process may have log file open."
intConstants = vbOKOnly + vbExclamation
intAns = objShell.Popup(strText, intTimeout, strTitle, _
intConstants)
End If
objLogFile.Close
Else
On Error GoTo 0
strTitle = "Logon Error"
strText = "Log cannot be written."
strText = strText & vbCrLf & "User may not have permissions,"
strText = strText & vbCrLf & "or log folder may not be shared."
intConstants = vbOKOnly + vbExclamation
intAns = objShell.Popup(strText, intTimeout, strTitle, intConstants)
End If
End If
Function GetIPAddresses()
' Based on a Michael Harris script, modified by Torgeir Bakken
'
' Returns array of IP Addresses as output
' by IPConfig or WinIPCfg...
'
' Win98/WinNT have IPConfig (Win95 doesn't)
' Win98/Win95 have WinIPCfg (WinNt doesn't)
'
' Note: The PPP Adapter (Dial Up Adapter) is
' excluded if not connected (IP address will be 0.0.0.0)
' and included if it is connected.
Dim objShell, objFSO, objEnv, strWorkFile, objFile
Dim arrData, intIndex, n, arrIPAddresses, arrParts
Set objShell = CreateObject("wscript.shell")
Set objFSO = CreateObject("scripting.filesystemobject")
Set objEnv = objShell.Environment("PROCESS")
If (objEnv("OS") = "Windows_NT") Then
strWorkFile = objEnv("TEMP") & "\" & objFSO.GetTempName
objShell.Run "%comspec% /c IPConfig >" & Chr(34) _
& strWorkFile & Chr(34), 0, True
Else
' WinIPCfg in batch mode sends output to
' filename WinIPCfg.out
strWorkFile = "WinIPCfg.out"
objShell.Run "WinIPCfg /batch", 0, True
End If
Set objFile = objFSO.OpenTextFile(strWorkFile)
arrData = Split(objFile. ReadAll, vbCrLf)
objFile.Close
objFSO.DeleteFile strWorkFile
arrIPAddresses = Array()
intIndex = -1
For n = 0 To UBound(arrData)
If (InStr(arrData(n), "IP Address") > 0) Then
arrParts = Split(arrData(n), ":")
If (InStr(Trim(arrParts(1)), "0.0.0.0") = 0) Then
intIndex = intIndex + 1
ReDim Preserve arrIPAddresses(intIndex)
arrIPAddresses(intIndex)= Trim(CStr(arrParts(1)))
End If
End If
Next
GetIPAddresses = arrIPAddresses
End FunctionEst-ce que quelqu'un aurait une idée de la source du problème ?
Merci d'avance.
- Modifié Phil Böhm jeudi 16 juillet 2015 14:00
jeudi 16 juillet 2015 13:58
Réponses
-
Ci-dessous le message de l'auteur qui détaile ce qu'il a modifié :
-------------------------------
Answerby:RobSampsonPosted on 2008-12-17 at 12:33:50ID: 23197771If the above is your full code, I've changed 103 from this
arrData = Split(objFile. ReadAll, vbCrLf)
to this
If Not objFile.AtEndOfStream Then arrData = Split(objFile. ReadAll, vbCrLf)
I've change 106 from this
objFSO.DeleteFile strWorkFile
to this
If objFSO.FileExists(strWorkFile) Then objFSO.DeleteFile strWorkFile
Then I added this
arrData = ""
above this
If Not objFile.AtEndOfStream Then arrData = Split(objFile. ReadAll, vbCrLf)
and add this
If IsArray(arrData) Then
around the For loop that goes through the array.
That should fix your problems.
Regards,
Rob.---------------------------------------
- Marqué comme réponse Emile Supiot mercredi 2 septembre 2015 08:02
jeudi 16 juillet 2015 21:02
Toutes les réponses
-
Salut,
Quelqu'un a eu la même erreur sur ce script, c'est la fonction GetIPAddresses() qui pose problème. Regarde ce thread, tu peux essayer de recopier le code proposé :
http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_23992039.html
jeudi 16 juillet 2015 14:59 -
C'est payant pour voir la solution ... Pourrais-tu la copier sur le forum ?jeudi 16 juillet 2015 15:10
-
Ah OK, je pensais que c'était possible de consulter 2-3 forums avant d'être bloqué. Voici le code de la fonction proposé :
Function GetIPAddresses() ' Based on a Michael Harris script, modified by Torgeir Bakken ' ' Returns array of IP Addresses as output ' by IPConfig or WinIPCfg... ' ' Win98/WinNT have IPConfig (Win95 doesn't) ' Win98/Win95 have WinIPCfg (WinNt doesn't) ' ' Note: The PPP Adapter (Dial Up Adapter) is ' excluded if not connected (IP address will be 0.0.0.0) ' and included if it is connected. Dim objShell, objFSO, objEnv, strWorkFile, objFile Dim arrData, intIndex, n, arrIPAddresses, arrParts Set objShell = CreateObject("wscript.shell") Set objFSO = CreateObject("scripting.filesystemobject") Set objEnv = objShell.Environment("PROCESS") If (objEnv("OS") = "Windows_NT") Then strWorkFile = objEnv("TEMP") & "\" & objFSO.GetTempName objShell.Run "%comspec% /c IPConfig >" & Chr(34) _ & strWorkFile & Chr(34), 0, True Else ' WinIPCfg in batch mode sends output to ' filename WinIPCfg.out strWorkFile = "WinIPCfg.out" objShell.Run "WinIPCfg /batch", 0, True End If Set objShell = Nothing Set objFile = objFSO.OpenTextFile(strWorkFile) arrData = "" If Not objFile.AtEndOfStream Then arrData = Split(objFile. ReadAll, vbCrLf) objFile.Close Set objFile = Nothing objFSO.DeleteFile strWorkFile Set objFSO = Nothing arrIPAddresses = Array() intIndex = -1 If IsArray(arrData) Then For n = 0 To UBound(arrData) If (InStr(arrData(n), "IP Address") > 0) Then arrParts = Split(arrData(n), ":") If (InStr(Trim(arrParts(1)), "0.0.0.0") = 0) Then intIndex = intIndex + 1 ReDim Preserve arrIPAddresses(intIndex) arrIPAddresses(intIndex)= Trim(CStr(arrParts(1))) End If End If Next End If
Next
GetIPAddresses = arrIPAddresses
End Function- Modifié Julien DECORMON jeudi 16 juillet 2015 20:57
- Proposé comme réponse Julien DECORMON jeudi 16 juillet 2015 21:41
jeudi 16 juillet 2015 20:55 -
Merci , mais est-ce que tu as quelques détails ?
Est-ce que le code que tu as collé est le bon pour remédier au problème ?
Merci !
jeudi 16 juillet 2015 20:57 -
Ci-dessous le message de l'auteur qui détaile ce qu'il a modifié :
-------------------------------
Answerby:RobSampsonPosted on 2008-12-17 at 12:33:50ID: 23197771If the above is your full code, I've changed 103 from this
arrData = Split(objFile. ReadAll, vbCrLf)
to this
If Not objFile.AtEndOfStream Then arrData = Split(objFile. ReadAll, vbCrLf)
I've change 106 from this
objFSO.DeleteFile strWorkFile
to this
If objFSO.FileExists(strWorkFile) Then objFSO.DeleteFile strWorkFile
Then I added this
arrData = ""
above this
If Not objFile.AtEndOfStream Then arrData = Split(objFile. ReadAll, vbCrLf)
and add this
If IsArray(arrData) Then
around the For loop that goes through the array.
That should fix your problems.
Regards,
Rob.---------------------------------------
- Marqué comme réponse Emile Supiot mercredi 2 septembre 2015 08:02
jeudi 16 juillet 2015 21:02 -
ça m'a l'air pas mal, ça a corrigé qqu'un qui avait la même erreur (error :Input past end of file (800a003e)
line 118).- Marqué comme réponse Emile Supiot mercredi 2 septembre 2015 08:02
- Non marqué comme réponse Emile Supiot mercredi 2 septembre 2015 08:02
jeudi 16 juillet 2015 21:06 -
Je vais essayer ça de suite !
Merci beaucoup pour ton aide.
jeudi 16 juillet 2015 21:07 -
J'ai modifié et maintenant j'Ai cette erreur :
jeudi 16 juillet 2015 21:19 -
supprime le 'Next' a la ligne 133 (a la fin) ?jeudi 16 juillet 2015 21:23
-
Ça semble fonctionner
Merci !
jeudi 16 juillet 2015 21:36