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

  • 相关阅读:
    TCP,UDP协议下的socket通信
    socket套接字
    野指针
    各种数据类型与零值比较规范
    【C++复习】1.1基本概念
    【转载】C++中的static关键字的总结
    Windows10下搭建汇编语言开发环境(利用DOSBOX和MASM32)
    初试ARM开发板
    命令行中编译和运行JAVA程序出现“错误: 找不到或无法加载主类”
    用c语言产生随机数的方法
  • 原文地址:https://www.cnblogs.com/ryhan/p/2036529.html
Copyright © 2011-2022 走看看