1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| '========================================================================
'Subprocedure to update value of ini variables value
Sub WriteToEnvironment(sParam ,sValue)
'Declare the required variables
Dim oFSO, oFile, oTxtStream, sLine, sNewTextStream, vpath
'Create the application object for FileSystemObject
Set oFSO = CreateObject("Scripting.FileSystemObject")
'Declare the file input/output constants
Const ForReading = 1, ForWriting = 2, ForAppending = 8
'Declare Tristate values constant used to indicate the format of the opened file
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
'Get the file from the file specified in environment variable
'Set oFile = oFSO.GetFile(Environment("iniPath"))
Set oFile = oFSO.GetFile("E:\script_automat\parametrage.ini")
'Open the ini file for reading purpose
Set oTxtStream = oFile.OpenAsTextStream(ForReading, TristateUseDefault)
'Read the file till the end
While Not oTxtStream.AtEndOfStream
'Read the file line by line
sLine = oTxtStream.ReadLine
sParameter = Array()
'Spilt the ini variable by delimiter
sParameter = Split(sLine, "=")
'If the ini variable name matches to required then modify the value with new value
If sParameter(0) = sParam Then
sLine = sParam & "=" & sValue
End If
sNewTextStream = sNewTextStream & sLine & vbCrLf
Wend
'close the stream object
oTxtStream.Close
'Create the application object for FileSystemObject
Set oFSO = CreateObject("Scripting.FileSystemObject")
'Set oFile = oFSO.GetFile(" E:\script_automat\parametrage.au3")
Set oFile = oFSO.GetFile("E:\script_automat\parametrage.ini")
'Get the file from the file specified in environment variable
'Set oFile = oFSO.GetFile(Environment("iniPath"))
'Open the ini file for writhing purpose
Set oTxtStream = oFile.OpenAsTextStream(ForWriting, TristateUseDefault)
'Write the new stream data to file
oTxtStream.Write sNewTextStream
'Close the stream object
oTxtStream.Close
End Sub |
Partager