Hello everyone,
I'm having a problem with a script where I want to check a log and upon finding a successful install message, I'm writing this to another file.
Please eyeball the embedded script to see if anything jumps out at you.
It was working for a while and all of a sudden started generating the "Permission Denied" on the file I'm trying to access.
Kind Regards
'Option Explicit
'On error resume next
'---------------------------------Declaration section of Script-------------------------
Dim Astring
Dim Bstring
Dim objFSO
Dim objFile
Dim strLine
Dim SearchResult
Dim LogFile
Dim ResultFile
Dim objLogFile
Dim windowsdir
Dim UserPath
Dim ObjResultFile
Dim ObjResultFile2
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
'--------------------------------Worker Sectoin of script---------------------------------
set shell = WScript.CreateObject("WScript.Shell")
windowsdir = shell.ExpandEnvironmentStrings("%temp%")
UserPath = shell.ExpandEnvironmentStrings("%USERPROFILE%")
MsgBox(windowsdir)
MsgBox(UserPath)
ResultFile = windowsdir & "\" & "resultFile.txt"
'ObjResultFile2 = windowsdir & "\" & "ResultFile.txt"
objLogFile = windowsdir & "\" & "fso.txt"
' MsgBox (ResultFile)
MsgBox (objLogFile)
set Astring = "Installation completed successfully."
set Bstring = "Microsoft Outlook installation status =0"
MsgBox (Astring)
Set ObjFso = CreateObject("Scripting.FileSystemObject")
Set ObjLogFile = ObjFspenTextFile(windowsdir & "\" & "fso.txt", 1)
'Set ResultFile = ObjFspenTextFile(windowsdir & "\" & "resultfile.txt", ForAppending)
Set ResultFile = objFSO.OpenTextFile(windowsdir & "\" & "resultfile.txt", ForAppending)
Do Until objLogFile.AtEndofStream
strLine = objLogfile.ReadLine
SearchResult = InStr(strLine, Astring)
MsgBox (SearchResult)
If SearchResult = Astring Then
set objFile = objFSO.OpenTextFile(ResultFile, ForWriting)
objFile.Write(Astring)
'objfile.Close
End if
Loop
'set objFSO = CreateObject("Scripting.FileSystemObject")
MsgBox (SearchResult)
Set ResultFile = objFSO.OpenTextFile(windowsdir & "\" & "resultfile.txt", 8)
Do Until objLogFile.AtEndOfStream
strLine = objLogfile.ReadLine
If SearchResult <> 0 Then
set objFile = objFSO.OpenTextFile(ResultFile, ForWriting)
objFile.Write(Bstring)
End If
Loop
I'm having a problem with a script where I want to check a log and upon finding a successful install message, I'm writing this to another file.
Please eyeball the embedded script to see if anything jumps out at you.
It was working for a while and all of a sudden started generating the "Permission Denied" on the file I'm trying to access.
Kind Regards
'Option Explicit
'On error resume next
'---------------------------------Declaration section of Script-------------------------
Dim Astring
Dim Bstring
Dim objFSO
Dim objFile
Dim strLine
Dim SearchResult
Dim LogFile
Dim ResultFile
Dim objLogFile
Dim windowsdir
Dim UserPath
Dim ObjResultFile
Dim ObjResultFile2
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
'--------------------------------Worker Sectoin of script---------------------------------
set shell = WScript.CreateObject("WScript.Shell")
windowsdir = shell.ExpandEnvironmentStrings("%temp%")
UserPath = shell.ExpandEnvironmentStrings("%USERPROFILE%")
MsgBox(windowsdir)
MsgBox(UserPath)
ResultFile = windowsdir & "\" & "resultFile.txt"
'ObjResultFile2 = windowsdir & "\" & "ResultFile.txt"
objLogFile = windowsdir & "\" & "fso.txt"
' MsgBox (ResultFile)
MsgBox (objLogFile)
set Astring = "Installation completed successfully."
set Bstring = "Microsoft Outlook installation status =0"
MsgBox (Astring)
Set ObjFso = CreateObject("Scripting.FileSystemObject")
Set ObjLogFile = ObjFspenTextFile(windowsdir & "\" & "fso.txt", 1)
'Set ResultFile = ObjFspenTextFile(windowsdir & "\" & "resultfile.txt", ForAppending)
Set ResultFile = objFSO.OpenTextFile(windowsdir & "\" & "resultfile.txt", ForAppending)
Do Until objLogFile.AtEndofStream
strLine = objLogfile.ReadLine
SearchResult = InStr(strLine, Astring)
MsgBox (SearchResult)
If SearchResult = Astring Then
set objFile = objFSO.OpenTextFile(ResultFile, ForWriting)
objFile.Write(Astring)
'objfile.Close
End if
Loop
'set objFSO = CreateObject("Scripting.FileSystemObject")
MsgBox (SearchResult)
Set ResultFile = objFSO.OpenTextFile(windowsdir & "\" & "resultfile.txt", 8)
Do Until objLogFile.AtEndOfStream
strLine = objLogfile.ReadLine
If SearchResult <> 0 Then
set objFile = objFSO.OpenTextFile(ResultFile, ForWriting)
objFile.Write(Bstring)
End If
Loop