我试图将一个简单的程序发送到消息框中"autorun.inf"
示例:
[Autorun]
open=setup.exe
icon=setup.exe,0
我如何定义所说的行 即使它不是第二行,它可能是第五行,我的意思是在一些文本之后......
open=setup.exe
并修剪文件名及其扩展名?
答案 0 :(得分:0)
Dim FilePath As String = "E:\run.inf"
Dim INF As String = My.Computer.FileSystem.ReadAllText(FilePath)
INF = INF.ToLower
Dim StartIndex As Integer = INF.IndexOf("open=") + 5
Dim EndIndex As Integer = INF.IndexOf(vbCrLf, StartIndex)
Dim ExecutableName As String = ""
If StartIndex = 4 Then
MsgBox("the executable file name could not found at file :" & vbCrLf & FilePath)
Else
If EndIndex = -1 Then
ExecutableName = INF.Substring(StartIndex)
Else
ExecutableName = INF.Substring(StartIndex, EndIndex - StartIndex)
End If
MsgBox("The Executable Name is " & Chr(34) & ExecutableName & Chr(34))
End If
首先我们读取INF文件的所有文本并将其大小写更低,以便我们可以搜索更低的"open="
。
然后我们将可执行文件名的起始索引和结束索引定义为字符串"open="
之后的开头和换行符vbCrlf
之前的结尾。
最后得到可执行文件名称并在MsgBox
中显示。