Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Vbscript Generating Permission denied

Status
Not open for further replies.

Councilk

MIS
May 14, 2003
72
US
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 = ObjFso_OpenTextFile(windowsdir & "\" & "fso.txt", 1)
'Set ResultFile = ObjFso_OpenTextFile(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
 
Depends where %temp% points to. If it points to the same directory as some other user, then you won't be abole to overwrite the files. Best delete all temp files when you've finished.

Alternative 2: is there a script still running which is accessing those files.

Alternative 3: Are you looking at those files in another window?

Alternative 4: Does the temp directory exist?

These are the common reasons why you get access denied.
 
Thanks XWB, I was able to resolve this issue, but I'm not sure if it was the file mode in which the file was opened.

Thanks for your input...

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top