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.
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.