2012-05-25 22 views
0

我需要通過ASP讀取WinCE 5.0中的設備文件系統中的.ini文件。以下是讀取文件的腳本。 但裝置不能夠創建類型的ActiveX對象 「Scripting.FileSystemObject的」如何在使用asp的設備中讀取WinCE 5.0 OS中的.ini文件

--------- 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)); 
} 
%> 
+0

檢查答案,或許它可以幫助你! –

回答

1

FSO(FileSystemObject的)無法在Windows CE

所以在CE存在必須是:

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

UPDATE文件引用是:MSCEFile.dll

注意我不知道,這是WinCE的5,由於工作是一箇舊的操作系統

文檔FSO differences between Windows and WinCE

+0

謝謝你Luka,我在我的代碼中添加了「FILECTL.FileSystem」,但得到了錯誤,解析腳本中的錯誤 Microsoft JScript運行時錯誤:'800a01ad' 說明:自動化服務器無法創建支持ddl的對象 爲此添加?請幫忙。謝謝。 – user1409360

+0

我已更新以提供更多信息 –

+0

MSCEFile.dll在WinCE 5上不能正常工作。他們的任何其他ddl是否讀取ini文件?謝謝。 – user1409360