Megan Schilling
Megan Schilling

Reputation: 1

Getting permission denied error when trying to create file for writing in VBScript

I keep getting permission denied when trying to open the second file here for writing. I know the first file opens fine as I can write it out to the screen and I have set write permissions for users. Is this so simple that I'm being blinded by it???

css_org = server.MapPath("style.css")
css_new = server.MapPath("new_style.css")           
Set fso = CreateObject("Scripting.FileSystemObject")
Const ForReading = 1 
Const ForWriting = 2        
Set objFile1 = fso.OpenTextFile (css_org, ForReading)
Set objFile2 = fso.OpenTextFile (css_new, ForWriting, True)  ' 500 error on this line

Upvotes: 0

Views: 1291

Answers (2)

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200293

Your code seems to be ASP, so you need to grant write permission to the user running the code (usually the service account running IIS), not the user who is logged into your web application.

Upvotes: 1

rory.ap
rory.ap

Reputation: 35270

Have you tried writing to the file outside of code to see if the user context can write to it? It's probably not an issue with your code. You may get a more informative error message if you try to write to it, say, with Notepad. Also, you could try using SysInternals' "Process Explorer" -- their "Find Handle" feature to test that file to see if there is some process locking it.

Upvotes: 0

Related Questions