【发布时间】:2012-03-11 01:58:56
【问题描述】:
我正在尝试编辑 ini 文件中的一行。 DeviceName=APPLE 到 DeviceName="用户输入"。我几乎从互联网上的点点滴滴那里得到它。它可以工作,除了最终结果是我的文件 jwalk.ini 在用户输入后具有正确的条目,但是 ini 文件已重命名为 .ini,在 ini 之前没有 jwalk。我肯定错过了什么。文件 jwalk.ini 已经存在,我只需要使用新的用户输入对其进行编辑,并保持文件名称不变。
我的脚本:
Const ForReading = 1
Const ForWriting = 2
Const OpenAsASCII = 0
Const CreateIfNotExist = True
Set objFSO = CreateObject("Scripting.FileSystemObject")
' Open existing file for read access.
strInput = "c:\MyFolder\jwalk.ini"
Set objInput = objFSO.OpenTextFile(strInput, ForReading)
' Prompt for device name.
strDeviceName = InputBox("Enter devicename", "JWalk PC Name or Session Name")
' Specify the new file name.
strOutput = "c:\MyFolder\" & strComputer & ".ini"
' Create new file with write access.
Set objOutput = objFSO.OpenTextFile(strOutput, _
ForWriting, CreateIfNotExist, OpenAsASCII)
' Process input file.
Do Until objInput.AtEndOfStream
' Read next line of the input file.
strLine = objInput.ReadLine
' Search for line to be modified.
' Make search case insensitive.
If (InStr(LCase(strLine), "devicename=") > 0) Then
' Replace the line.
' You could also modify the line.
strLine = "devicename=" & strDeviceName
End If
' Write line to the output file.
objOutput.WriteLine strLine
Loop
' Clean up.
objInput.Close
objOutput.Close
' Delete the original file.
objFSO.DeleteFile(strInput)
有什么想法吗?谢谢。
【问题讨论】:
标签: vbscript