Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 如何使用VBS脚本从.ini文件中删除一行_Windows_Batch File_Vbscript_Hta - Fatal编程技术网

Windows 如何使用VBS脚本从.ini文件中删除一行

Windows 如何使用VBS脚本从.ini文件中删除一行,windows,batch-file,vbscript,hta,Windows,Batch File,Vbscript,Hta,我正在尝试编写一个VBS脚本,以从.ini文件中删除一行。 但是,当我运行它时,会创建并重命名新文件(以及备份),但我要删除的行仍然存在? 我怎样才能解决这个问题 这是我的密码: Const ForReading = 1 Const ForWriting = 2 Const OpenAsASCII = 0 Const CreateIfNotExist = True Set objFSO = CreateObject("Scripting.FileSystemObject") Const Ove

我正在尝试编写一个VBS脚本,以从.ini文件中删除一行。 但是,当我运行它时,会创建并重命名新文件(以及备份),但我要删除的行仍然存在? 我怎样才能解决这个问题

这是我的密码:

Const ForReading = 1
Const ForWriting = 2
Const OpenAsASCII = 0
Const CreateIfNotExist = True

Set objFSO = CreateObject("Scripting.FileSystemObject")
Const OverwriteExisting = True

'Making a backup of the file
objFSO.CopyFile "C:\notes.ini" , "C:\notesBACKUP.ini"

'Setting input of file
strInput = "C:\notes.ini"
Set objInput = objFSO.OpenTextFile(strInput, ForReading)

'Setting temp output for new file with omitted line
strOutput = "C:\notes2.ini"

Set objOutput = objFSO.OpenTextFile(strOutput, _
ForWriting, CreateIfNotExist, OpenAsASCII)


Do Until objInput.AtEndOfStream

strLine = objInput.ReadLine

'Line with EXTMGR to be replaced when copying to new file
If (InStr(LCase(strLine), "EXTMGR") > 0) Then

'New line replacing old one
strLine = "#Deleted"
End If

objOutput.WriteLine strLine
Loop


objInput.Close
objOutput.Close


'Deleting the original file
objFSO.DeleteFile(strInput)

'Renaming the new file (with line removed) to the original filename
objFSO.MoveFile "C:\notes2.ini" , "C:\notes.ini"

您正在对字符串进行
LCASE
转换,然后在所有大写字母中查找字符串

将代码更改为:

If(InStr(strLine,“EXTMGR\u ADDINS”)>0)

您正在对字符串进行LCASE转换,然后在所有大写字母中查找字符串-看起来很奇怪。您要替换的INI文件中的哪一行?你能分享一下吗?是的-没有注意到,我使用的是我以前的脚本中的部分-这是我需要注释(或删除)的一行:EXTMGR_ADDINS=NCExtMgrIf(InStr(strLine,“EXTMGR_ADDINS”)>0)不起作用吗?是的,只是回去尝试了一下,效果很好。谢谢,我以前都没注意到,doh!