2013-10-31 20 views
0

這裏是一個代碼,我想在後臺運行,所以沒有windowmessages。它的含義是它檢查一個連接。如果沒有連接,則會向文件寫入錯誤。一個函數讀取該文件,如果有5行,它應該創建一個事件錯誤。問題是最後一部分無法正常工作。寫入文件的行,當有5行需要執行語句vbscript

我的問題是有人可以修復它或幫助我修復它。這裏是代碼:

strDirectory = "Z:\text2" 
strFile = "\foutmelding.txt" 
strText = "De connectie is verbroken" 
strWebsite = "www.helmichbeens.com" 


If PingSite(strWebsite) Then WScript.Quit 'Website is pingable - no further action required 
Set objFSO = CreateObject("Scripting.FileSystemObject") 

RecordSingleEvent 
If EventCount >= 5 Then 
    objFSO.DeleteFile strDirectory & strFile 
    Set WshShell = WScript.CreateObject("WScript.Shell") 
    strCommand = "eventcreate /T Error /ID 100 /L Scripts /D " & _ 
    Chr(34) & "Test event." & Chr(34) 
    WshShell.Run strcommand 
End if 
'------------------------------------ 
'Record a single event in a text file 
'------------------------------------ 
Sub RecordSingleEvent 
    If Not objFSO.FolderExists(strDirectory) Then objFSO.CreateFolder(strDirectory) 
    Set objTextFile = objFSO.OpenTextFile(strDirectory & strFile, 8, True) 
    objTextFile.WriteLine(Now & strText) 
    objTextFile.Close 
End sub 
'---------------- 
'Ping my web site 
'---------------- 
Function PingSite(myWebsite) 
    Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1") 
    objHTTP.Open "GET", "http://" & myWebsite & "/", False 
    objHTTP.SetRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MyApp 1.0; Windows NT 5.1)" 
    On Error Resume Next 
    objHTTP.Send 
    PingSite = (objHTTP.Status = 200) 
    On Error Goto 0 
End Function 
'----------------------------------------------- 
'Counts the number of lines inside the text file 
'----------------------------------------------- 
Function EventCount() 
    strData = objFSO.OpenTextFile(strDirectory & strFile,ForReading).ReadAll 
    arrLines = Split(strData,vbCrLf) 
    EventCount = UBound(arrLines) 
    Set objFSO = Nothing 
End Function 

這就是你可以複製它的代碼來看看你的自我。我感謝您的時間和intrest

電賀helmich

回答

0

使用Shell對象

If EventCount >= 5 Then 
    objFSO.DeleteFile strDirectory & strFile 
    Set WshShell = WScript.CreateObject("WScript.Shell") 
    Call WshShell.LogEvent(1, "Test Event") 
End if 

你並不需要運行一個單獨的命令

1

一點也沒有」的LOGEVENT方法因爲功能EventCount設置爲objFSO=nothing,所以,

If EventCount >= 5 Then 
    objFSO.DeleteFile strDirectory & strFile 

失敗

0

那不是的問題是這樣的

Windows主機腳本給出了一個錯誤

行:41 炭:錯誤的2 翻譯:此操作所需的數據尚未公佈 代碼:80070057 來源:WinHttp.WinHttpRequest 這就是問題,我不知道如何解決它

它有事情做,他無法讀取txtfile註冊表的線,然後不execu創建活動命令