2016-09-28 302 views
-3

因此,我有一個HTA,當我嘗試創建或打開文本文件記錄時遇到問題。HTA錯誤:無法完成操作,因爲錯誤8070000c

它正常工作對IE 11 64位Windows 7當我嘗試在Windows 10 64位,我得到以下錯誤:

無法完成因錯誤8070000c操作。

線的誤差是低於:

var fso = new ActiveXObject("Scripting.FileSystemObject"); 
    var f = fso.OpenTextFile('log\\log.txt',2,true); // <-- Error is on this line! 

這似乎像一個權限錯誤。我搜索了大約2個小時,無法確定原因/解決方案。

再次,它工作正常的Windows 7,但Windows 10

同HTA如下:

<!-- saved from url=(0014)about:internet --> 
<?xml version='1.0' encoding='UTF-8'?> 
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'> 
<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'> 
<head> 
<HTA:Application Border='yes' ContextMenu='no' Caption='no' Scroll='auto' Singleinstance='yes' Windowstate='maximize' application='yes'> 
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' /> 
<meta http-equiv='X-UA-Compatible' content='IE=9' /> 
<title>KIOSK</title> 
<link rel='stylesheet' href='css/style.css'> 
<link rel='stylesheet' href='https//code.jquery.com/ui/1.12.0/themes/base/jquery-ui.css'> 
<script type='text/javascript' src='jQuery/jquery-3.1.0.js'></script> 
<script type='text/javascript'> 
    // Log File. 
    function writeToLog(dStamp, msg) { 
     var loc = window.location.pathname; 
     var dir = loc.substring(0, loc.lastIndexOf('\\')); 
     dir = dir + '\\log\\log.txt'; 
     // alert(dir); 
     //Create FSO Object 
     var fso = new ActiveXObject("Scripting.FileSystemObject"); 
     //First, make sure the LOG exists 
     if (!fso.fileExists("log\\log.txt")) { 
      //alert("FILE DONT EXIST!"); 
      try { 
       var f = fso.OpenTextFile(dir,2,true); 
       f.close(); 
      } catch(e) { 
       alert("The following error was found: " + e); 
       return; 
      } 
     } else { 
      dtTime = new Date(); 
      //This function was added because if the log file gets over a certain size, I want to rename it and make a new one 
      var f = fso.OpenTextFile(dir,1,false); 
      var fSize = f.Size; 
      if (fSize > 1000000) { //If file is larger than 1Mb, rename and create new. 
       fileExists = true; 
       fileNumber = 0; 
       newFileName = f + "-" + (dtTime.getMonth() + 1) + "-" + dtTime.getDate() + "-" + dtTime.getFullYear(); 
       while (fileExists) { 
        if (fso.fileExists(newFileName)) { 
         fileNumber++; 
         newFileName = f + "-" + (dtTime.getMonth() + 1) + "-" + dtTime.getDate() + "-" + dtTime.getFullYear() + "_" + fileNumber; 
         fileExists = true; 
        } else { 
         fileExists = false; 
        } 
       } 

       fso.MoveFile(f, newFileName); 

       //And create my new one 
       f = fso.OpenTextFile(dir,2,true); 
       f.close(); 
      } 
     } 

     //Now, open the log file 
     var f = fso.OpenTextFile(dir, 8); 

     //Now, write to the log file 
     //First, check to see if we want a date stamp before this message 
     if (dStamp == true) { 
      dtTime = new Date(); 
      nLine = dtTime + "\t" + msg; 
     } else { 
      nLine = "\t" + msg; 
     } 

     f.WriteLine(nLine); 

     //Finally, close the log file... until next time... 
     f.close(); 
    } 
</script> 
<body ondragstart='return false' style='text-align:center;'> 
    <input type="button" onclick="writeToLog(true,'Test Log HTA');" value="Test Log" /> 
</body> 
</html> 

任何幫助表示讚賞。

+0

可能UAC,使用提升的特權運行'mshta.exe「your.hta」'。 – Lankymart

+0

你的時間可能會更好地花在離開HTA。微軟表示它是一項「傳統」技術。請參閱[此連接文章](https://connect.microsoft.com/IE/feedback/details/785055/hta-application-tag-does-not-work-in-ie10)官方文字。 –

+0

我明白HTA是傳統技術。不幸的是,這就是我現在正在處理的事情。 – dEf

回答

0

看起來我有一些不正確的值被傳遞給OpenTextFile,這基本上導致我所有的問題。 如果有人需要修正和「工作」腳本, :)

// Log File. 
function writeToLog(dStamp, msg) { 
    var loc = window.location.pathname; 
    var dir = loc.substring(0, loc.lastIndexOf('\\')); 
    dir = dir + '\\log\\log.txt'; 
    // alert(dir); 
    //Create FSO Object 
    var fso = new ActiveXObject("Scripting.FileSystemObject"); 
    //First, make sure the LOG exists 
    if (!fso.fileExists(dir)) { 
     //alert("FILE DONT EXIST!"); 
     try { 
      var f = fso.CreateTextFile(dir, true); 
      f.close(); 
     } catch(e) { 
      alert("The following error was found: " + e); 
      return; 
     } 
    } else { 
     dtTime = new Date(); 
     //This function was added because if the log file gets over a certain size, I want to rename it and make a new one 
     var f = fso.OpenTextFile(dir,1,true,0); 
     var fSize = f.Size; 
     if (fSize > 1000000) { //If file is larger than 1Mb, rename and create new. 
      fileExists = true; 
      fileNumber = 0; 
      newFileName = f + "-" + (dtTime.getMonth() + 1) + "-" + dtTime.getDate() + "-" + dtTime.getFullYear(); 
      while (fileExists) { 
       if (fso.fileExists(newFileName)) { 
        fileNumber++; 
        newFileName = f + "-" + (dtTime.getMonth() + 1) + "-" + dtTime.getDate() + "-" + dtTime.getFullYear() + "_" + fileNumber; 
        fileExists = true; 
       } else { 
        fileExists = false; 
       } 
      } 

      fso.MoveFile(f, newFileName); 

      //And create my new one 
      f = fso.CreateTextFile(dir, true); 
      f.close(); 
     } 
    } 

    //Now, open the log file 
    var f = fso.OpenTextFile(dir,8,true,0); 

    //Now, write to the log file 
    //First, check to see if we want a date stamp before this message 
    if (dStamp == true) { 
     dtTime = new Date(); 
     nLine = dtTime + "\t" + msg; 
    } else { 
     nLine = "\t" + msg; 
    } 

    f.WriteLine(nLine); 

    //Finally, close the log file... until next time... 
    f.close(); 
} 
相關問題