0

我需要通过 ASP 读取 WinCE 5.0 设备文件系统中的 .ini 文件。下面是读取文件的脚本。但设备无法创建“Scripting.FileSystemObject”类型的 ActiveX 对象

---------ReadINIFile.inc------

<%
function GetINIString(Section, KeyName, Default, FileName)
{
  var INIContents, PosSection, PosEndSection, sContents, Value, Found;

  //Get contents of the INI file As a string;
  INIContents = GetFile(FileName)

  //Find section;
  PosSection = InStr(1, INIContents, "[" + Section + "]", 1);
  if(PosSection>0)
  {
    //Section exists. Find end of section;
    PosEndSection = InStr(PosSection, INIContents, '\r\n' + "[");
    //?Is this last section?;
    if(PosEndSection == 0)
    { 
        PosEndSection = Len(INIContents)+1;
        //Separate section contents;
        sContents = Mid(INIContents, PosSection, PosEndSection - PosSection)
        if (InStr(1, sContents, '\r\n' + KeyName + "=", 1) > 0) 
        {
            Found = True;
            //Separate value of a key.;
            Value = SeparateField(sContents, '\r\n' + KeyName + "=", '\r\n');
        }
    }
  }
  if(isempty(Found))
  { 
    Value = Default;
  }
  return Value;
}

//Separates one field between sStart && sEnd

function SeparateField(sFrom,sStart,sEnd)
{
  var PosB;
  PosB = InStr(1, sFrom, sStart, 1);
  if(PosB > 0)
  {
    PosB = PosB + Len(sStart);
    var PosE;
    PosE = InStr(PosB, sFrom, sEnd, 1);
    if(PosE == 0)
    { 
        PosE = InStr(PosB, sFrom, '\r\n', 1);
    }
    if (PosE == 0) 
    {
        PosE = Len(sFrom) + 1;
    }
    SeparateField = Mid(sFrom, PosB, PosE - PosB);
  }
}


//File functions

function GetFile(FileName){
  var FS;
  FS = new ActiveXObject("Scripting.FileSystemObject");
  //Go To windows folder if(full path ! specified
  if(InStr(FileName, "%3A%5C") = 0 && Left (FileName,2)!="\\")
  { 
    FileName = FS.GetSpecialFolder(0) + "1" + FileName;
  }
  //On Error Resume Next

  return FS.OpenTextFile(FileName).ReadAll;
}

function WriteFile(FileName,Contents)
{
  var FS;
  FS = new ActiveXObject("Scripting.FileSystemObject");
      //On Error Resume Next

      //Go To windows folder if(full path ! specified
      if(InStr(FileName, "%3A%5C") == 0 && Left (FileName,2)!=="/")
      {
        FileName = FS.GetSpecialFolder(0) + "1" + FileName;
      }

  var OutStream;
  OutStream = FS.OpenTextFile(FileName, 2, True);  
}
function GetINIStringVirtual(Section, KeyName, Default, FileName)
{
  return GetINIString(Section, KeyName, Default,  Server.MapPath(FileName));
}
%>
4

1 回答 1

1

Windows CE中FSO不存在 (FileSystemObject)

所以在 CE 中必须是:

FS = new ActiveXObject("FILECTL.FileSystem");

更新文件参考是:MSCEFile.dll

注意我不确定这是否适用于 WinCE 5,因为它是旧操作系统

Windows 和 WinCE 之间的文档 FSO 差异

于 2012-05-25T07:26:54.000 回答