如何读取一个.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
投稿

猜你喜欢

  • 相同记录行如何取最大值

    2008-07-26 12:32:00
  • 使用SQL语句 INNER JOIN 联接表

    2008-04-27 20:31:00
  • 利用css的clear属性搞定广告文字环绕效果

    2008-05-24 13:48:00
  • asp如何在页面中实现对电子信箱的访问?

    2010-06-26 12:34:00
  • CSS在页面布局中实现div水平居中的方法总结

    2008-06-03 12:09:00
  • QCon大会散记

    2010-05-03 14:19:00
  • 为你的ASP程序作一个负载测试

    2008-10-23 13:48:00
  • asp GetString的用法

    2008-06-12 13:46:00
  • SQL事务用法begin tran,commit tran和rollback tran的用法

    2012-01-05 18:58:51
  • js鼠标事件大全

    2007-08-13 15:56:00
  • my.ini(my.cnf)与mysql优化指南

    2009-12-15 16:20:00
  • 数据仓库基本报表制作过程中的SQL写法

    2008-11-25 12:17:00
  • 用YSlow评分插件分析我们页面

    2008-08-26 11:48:00
  • 如何在SQL Server中由原子建立分子查询

    2009-01-20 16:01:00
  • 也谈谈DIV+CSS的牛角尖

    2007-11-16 16:12:00
  • javascript拼音搜索引擎

    2011-08-29 15:42:14
  • 将滚动条(scrollbar)保持在最底部的方法

    2008-02-21 10:05:00
  • [翻译]标记语言和样式手册 Chapter 15 为body指定样式

    2008-02-21 12:36:00
  • Sql2005启用和关闭xp_cmdshell功能

    2008-09-29 15:37:00
  • 只有mdf文件的数据库附加失败的修复方法分享(置疑、只读)

    2012-02-12 15:55:17
  • asp之家 网络编程 m.aspxhome.com