zoukankan      html  css  js  c++  java
  • 用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

  • 相关阅读:
    前后端分离基于Oauth2的SSO单点登录怎样做?
    Spring Security基于Oauth2的SSO单点登录怎样做?一个注解搞定
    微服务业务监控和行为分析怎么做?试试日志埋点
    Spring Cloud Gateway的动态路由怎样做?集成Nacos实现很简单
    Spring Cloud异步场景分布式事务怎样做?试试RocketMQ
    Apache RocketMQ 消息队列部署与可视化界面安装
    Spring Cloud同步场景分布式事务怎样做?试试Seata
    实施微服务架构的关键技术
    Spring Cloud开发人员如何解决服务冲突和实例乱窜?(IP实现方案)
    独立博客,从零到千万访问,这三年我都做了什么
  • 原文地址:https://www.cnblogs.com/ryhan/p/2036529.html
Copyright © 2011-2022 走看看