我需要通过 ASP 读取 WincE 5. 0 设备文件系统中的. ini 文件。 下面是读文件的脚本 。 < streng > 但设备无法创建“ scripting. FileSystemObject” 类型的 AFentX 对象 strong>
- - - - - - - - - - - - - - - - - - - - - - - -
<%
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,
+ "[");
//?Is this last section?;
if(PosEndSection == 0)
{
PosEndSection = Len(INIContents)+1;
//Separate section contents;
sContents = Mid(INIContents, PosSection, PosEndSection - PosSection)
if (InStr(1, sContents,
+ KeyName + "=", 1) > 0)
{
Found = True;
//Separate value of a key.;
Value = SeparateField(sContents,
+ KeyName + "=",
);
}
}
}
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,
, 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));
}
%>