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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Permissions Denied on OpenTextFile - interesting twist?!

Status
Not open for further replies.

jchamber

Technical User
Mar 16, 2010
2
0
0
CA
Hi, I have a script that is giving me a permissions denied error when trying to OpenTextFile. The file is being opened for writing, and was previously opened for reading but WAS closed.

The weird thing is, I work in an managed XP environment. The script will run fine on our old XP image, but on our new image it is giving me the error, not sure what is causing it, there are not obvious differences in the two images to me that could be causing this.

The code segment is:

'Configuring machine.config file

Const ForReading = 1
Const ForWriting = 2

'WScript.Echo " "
'WScript.Echo "Please enter Domain\UserName"

'strDomainUser = wscript.StdIn.ReadLine
'WScript.Echo "Please enter password"
'strPassword = wscript.StdIn.ReadLine


strFileName = "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG\machine.config"
strOldText = "<processModel autoConfig=""true"" />"
strNewText = "<processModel autoConfig=""true"" enable=""true"" userName=""labcorp\developerName"" password=""password"" />"


Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strFileName, ForReading)

strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, strOldText, strNewText)

Set objFile = objFSO.OpenTextFile(strFileName, ForWriting) 'This is line 157, where it says the error is
objFile.WriteLine strNewText
objFile.Close

I have checked and rechecked all the permissions, they are properly set. I have no idea what is causing this.

Any help you can give would be very much appreciated.
 
What user are you running the script as?

You can set/check the permissions from a cmd prompt using cacls.
 
Might be worth checking the owning directory too.
 
I'm running the scripts under an account which is part of the local administrators group. Local admin has full control over the script, the file it's trying to modify, and the containing folders of each.

Not sure if by owning directly that's what you meant.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top