用FileSystemObject对象读取INI 文件 支持 VB读INI VBS读INI ASP 读INI

'作者:CSDN 许仙
'Homepage : jjweb.126.com
'MSN :Coderxu#hotmail.com
'QQ:19030300
'转载请保持文章完整,保存以上作者信息 请珍惜他人劳动成果


由于卡巴斯基 太厉害 弄的 OFFCIE编写的程序 调用API读取配置文件都不可以 于是 想到了用FileSystemObject对象读取INI 文件 代码如下, 修改了一下, 同时 支持了 VBS 当然 也支持ASP 网页读配置文件了....


VB代码
Public Function GetIni1(ByVal strPrimary As String, ByVal strSubKey As String, ByVal strIniFilePath As String) As String
    Dim myFso As FileSystemObject
    Dim MyFile As TextStream

    Dim intCount As Integer, strState As String
    Set myFso = New FileSystemObject
    Set MyFile = myFso.OpenTextFile(strIniFilePath, 1, False, False)
    With MyFile
        Do Until .AtEndOfStream
            If intCount = 0 Then
                If .ReadLine = "[" & strPrimary & "]" Then
                    intCount = 1
                End If
            Else
                strState = .ReadLine
                If UCase(Left(strState, Len(strSubKey & "="))) = UCase(strSubKey & "=") Then
                    GetIni1 = Right(strState, Len(strState) - Len(strSubKey & "="))
                End If
            End If
        Loop
        .Close
    End With
    Set MyFile = Nothing
    Set myFso = Nothing
End Function

VBS 代码

'将以下信息 拷贝到文本里 改名.vbs运行查看效果
msgbox GetIni ("boot loader","timeout","c:\boot.ini")

'VBS读取  INI 配置文件

Function GetIni( strPrimary  ,  strSubKey,  strIniFilePath )
    Dim myFso
    Dim MyFile
    Dim intCount , strState
    Set myFso =  CreateObject("Scripting.FileSystemObject")

    Set MyFile = myFso.OpenTextFile(strIniFilePath, 1, False, False)
    With MyFile
        Do Until .AtEndOfStream
            If intCount = 0 Then
                If .ReadLine = "[" & strPrimary & "]" Then
                    intCount = 1
                End If
            Else
                strState = .ReadLine
                If UCase(Left(strState, Len(strSubKey & "="))) = UCase(strSubKey & "=") Then
                    GetIni = Right(strState, Len(strState) - Len(strSubKey & "="))
                End If
            End If
        Loop
        .Close
    End With
    Set MyFile = Nothing
    Set myFso = Nothing
End Function


本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/hot1kang1/archive/2006/07/04/875861.aspx

posted on 2011-05-04 15:06 ryhan 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/ryhan/archive/2011/05/04/2036529.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值