如何读取一个.ini文件?

来源:asp之家 时间:2009-11-18 20:58:00 

以发布目录为例:

<OBJECT ID="agobjOraSession" RUNAT="Server" PROGID="OracleInProcServer.XOraSession" SCOPE="APPLICATION">
</OBJECT>
<SCRIPT LANGUAGE=VBScript RUNAT=Server>
Const CONST_FL_NAME = "\GetAttributeCode.ini"
Const CONST_FL_FORREADING = 1
Const CONST_DB_SECTION = "[DB_CONNECTION]"Sub Application_OnStart
On Error Resume Next
        
  Dim objFs      
  Dim objTs          
  Dim strLineData      
  Dim flgSection      
  Dim strTempData  
        
  Application("Service") = ""
  Application("User") = ""
  strLineData = ""  
  strTempData = ""
  flgSection = False

  Set objFs = Server.CreateObject ("Scripting.FileSystemObject")
  Set objTs = objFs.OpenTextFile(Server.MapPath(CONST_FL_NAME),CONST_FL_FORREADING,False)
  If Err.Number <> 0 Then
    Err.Clear 
     Set objTs = Nothing
    Set objFs = Nothing
    Exit Sub
  End If
While Not objTs.AtEndOfStream
    strLineData = objTs.ReadLine
   If Trim(strLineData) <> "" Then
        If flgSection = True And Mid(strLineData,1,1) = "[" And _
        Mid(strLineData,Len(strLineData),1) = "]" Then
       objTs.Close
         Set objTs = Nothing
       Set objFs = Nothing
       Exit Sub
      End If 
    
      If strLineData = CONST_DB_SECTION Then
       flgSection = True
     End If
If flgSection = True Then
      If Mid(strLineData,1,7) = "Service" Then
        strTempData = Trim(Mid(strLineData,8,Len(strLineData)-7))
        If Mid(strTempData,1,1) = "=" Then
          strTempData = Trim(Mid(strTempData,2,Len(strTempData)-1))
          Application.Lock 
           Application("Service") = Mid(strTempData,2,Len(strTempData)-2)
          Application.UnLock 
       End If
    End If
    If Mid(strLineData,1,4) = "User" Then
        strTempData = Trim(Mid(strLineData,5,Len(strLineData)-4))
        If Mid(strTempData,1,1) = "=" Then
        strTempData = Trim(Mid(strTempData,2,Len(strTempData)-1))
        Application.Lock 
        Application("User") = Mid(strTempData,2,Len(strTempData)-2)
        Application.UnLock 
      End If
End If
End If
End If
Wend
objTs.Close
Set objTs = Nothing
Set objFs = Nothing
End Sub
</SCRIPT>


 

标签:ini,文件,asp
0
投稿

猜你喜欢

  • Maven中央仓库正式成为Oracle官方JDBC驱动程序组件分发中心(推荐)

    2024-01-26 05:26:27
  • 基于.net开发的遵循web标准的个人站点程序包下载

    2023-07-21 12:37:57
  • python 3.6 +pyMysql 操作mysql数据库(实例讲解)

    2024-01-19 16:38:39
  • python爬虫之验证码篇3-滑动验证码识别技术

    2021-08-19 07:15:38
  • Python读取视频的两种方法(imageio和cv2)

    2023-10-04 13:45:06
  • golang中defer的关键特性示例详解

    2023-08-06 06:12:45
  • PyQt5实现画布小程序

    2022-03-02 07:37:46
  • 简单实现SQLServer转MYSQL的方法

    2024-01-21 20:12:13
  • FileSystemObject 示例代码

    2008-10-24 08:54:00
  • python中for循环输出列表索引与对应的值方法

    2023-05-01 16:59:24
  • Python中使用matplotlib模块errorbar函数绘制误差棒图实例代码

    2022-11-09 17:01:42
  • asp如何设定程序的执行次数?

    2010-05-18 18:31:00
  • MySQL库表名大小写的选择

    2024-01-16 13:54:35
  • Python利用tkinter和socket实现端口扫描

    2022-05-08 11:53:23
  • 实例讲解Python中SocketServer模块处理网络请求的用法

    2021-04-16 13:25:27
  • ThinkPHP视图查询详解

    2024-05-03 15:52:08
  • 微信小程序开发之数据存储 参数传递 数据缓存

    2024-04-19 09:49:44
  • Oracle中执行动态SQL

    2024-01-19 20:55:37
  • Mysql 数据库常用备份方法和注意事项

    2024-01-17 15:43:25
  • Pytorch.nn.conv2d 过程验证方式(单,多通道卷积过程)

    2021-12-24 13:28:27
  • asp之家 网络编程 m.aspxhome.com