如何使用asp在设备中从WinCE 5.0 OS读取.ini文件

时间:2012-05-25 06:41:30

标签: javascript activex windows-ce

我需要通过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));
}
%>

1 个答案:

答案 0 :(得分:1)

Windows CE中不存在FSO(FileSystemObject)

所以CE必须是:

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

更新文件参考为:MSCEFile.dll

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

文档 FSO differences between Windows and WinCE