/build/static/layout/Breadcrumb_cap_w.png

vbscript throwing file not found error on wins2008

hi,
i have a vbscript custom action which is stored in the custom action.
the code works fine outside of the msi as a vbs.
if i add it, then a file not found error is thrown. no properties are used so its not the sequence of the custom action that is the problem.
the location of the file is C:\Windows\System32\inetsrv\config\applicationHost.config.
the file always exists in this location. to investigate i copied the file to C:\ and the script worked. i then added c:\windows and it worked. then when i added c:\Windows\System32 the file not found error appeared again. i am testing on wins2008 server.
this is very odd. i have copied the code, if anyone would mind taking a look.



Option Explicit
Const ForReading = 1
Const ForWriting = 2
Const stars = "***** "
'Initialisation
Dim strFileName, strOldText, strNewText, strText
Dim strWindowsFolderPath, objFSO, objFile,objShell
strFileName = "C:\Windows\System32\inetsrv\config\applicationHost.config"
'strFileName = "C:\Windows\System32\applicationHost.config"
strOldText = "<add segment=""bin"" />"
strNewText = ""
Set objShell = CreateObject("WScript.Shell")
On Error Resume Next
'==========================================================================
Err.Clear ()

Set objFSO = CreateObject("Scripting.FileSystemObject") ' create file system object

If (Err.Number <> 0) Then
msiLog "There was an error creating the file system object. Error Descripton "& Err.Descriptio & " Error Number "& Err.Number

Else


Set objFile = objFSO.OpenTextFile(strFileName, ForReading) ' open config file for reading

If (Err.Number <> 0) Then
' report error to msi log file
msiLog "There was an error opening the file "& strFileName& " Error Descripton " & Err.Description & "Error Number "& Err.Number

End If

strText = objFile.ReadAll ' read content and store in strText

If (Err.Number <> 0) Then

' report error to msi log file
msiLog "There was an error reading the file "& strFileName&"Error Descripton "& Err.Description & "Error Number "& Err.Number &Err.Source

Else
objFile.Close
strNewText = Replace(strText, strOldText, strNewText)
Set objFile = objFSO.OpenTextFile(strFileName, ForWriting)

If (Err.Number <> 0) Then

' report error to msi log file
msiLog "There was an error opening the file for writing "& strFileName&"Error Descripton "& Err.Description & "Error Number "& Err.Number

End If

objFile.WriteLine strNewText


If (Err.Number <> 0) Then

' report error to msi log file
msiLog "There was an error writing the new content "&strOldText&" to "& strFileName&"Error Descripton "& Err.Description & "Error Number "& Err.Number

End If

objFile.Close

End If

End If
Set objShell = Nothing'Clean Up
Set objFSO = Nothing'Clean Up
'==========================================================================
Function msiLog(Message)
MsgBox Message
Const msiMessageTypeInfo = &H04000000
Dim Record : Set Record = Nothing
Set Record = Session.Installer.CreateRecord(1)
Record.StringData(1) = Message
Session.Message msiMessageTypeInfo, Record
Set Record = Nothing
End Function
'==========================================================================

0 Comments   [ + ] Show comments

Answers (1)

Posted by: anonymous_9363 14 years ago
Red Belt
0
Have you tried using either the relevant environment variable or the FileSystemObject's GetSpecialFolder method to return the Windows System folder?

Also, if I'm not wrong, applicationHost.config is an XML file? You'd be much better to use the MS XML Parser object to read/write to XML: handling them as flat files is fraught with danger.
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ