未创建批处理文件

时间:2013-06-12 19:27:33

标签: asp-classic batch-file

我的代码应该在我的c:\上创建一个批处理文件。它应该在onclient上单击我的按钮创建它。当我点击按钮时,它不会在该位置创建文件。我错过了代码吗?

 function SubmitForm() {

    if (document.getElementById("hawbtxt").value == "") {
        alert("Please enter the HAWB (B/L)!");
        return false;
    }
    if (document.getElementById("invrefpotxt").value == "") {
        alert("Please enter the INV/REF/PO!");
        return false;
    }
    if (document.getElementById("hppartnumtxt").value == "") {
        alert("Please enter the HP PART NUM!");
        return false;
    }
    if (document.getElementById("iecpartnumtxt").value == "") {
        alert("Please enter the IEC PART NUM!");
        return false;
    }
    if (document.getElementById("qtytxt").value == "") {
        alert("Please enter the QUANTITY!");
        return false;
    }
    if (document.getElementById("bulkstxt").value == "") {
        alert("Please enter the BULKS!");
        return false;
    }
    if (document.getElementById("boxplttxt").value == "") {
        alert("Please enter the BOX/PLT!");
        return false;
    }
    if (document.getElementById("rcvddatetxt").value == "") {
        alert("Please enter the DATE!");
        return false;
    }
    if (document.getElementById("statustxt").value == "") {
        alert("Please enter the STATUS!");
        return false;
    }
    if (document.getElementById("carriertxt").value == "") {
        alert("Please enter the CARRIER!");
        return false;
    }
    if (document.getElementById("shippertxt").value == "") {
        alert("Please enter the SHIPPER!");
        return false;

    }
    alert("called");

    var sText, s;
    var fso = new ActiveXObject("Scripting.FileSystemObject");

    if (!fso.FileExists("C:\\temp\\COO_BTO_Test.bat")) {
        s = fso.CreateTextFile("C:\\temp\\COO_BTO_Test.bat", true);
        sText = "@echo off";
        s.WriteLine(sText);

        sText = ":Lbl";
        s.WriteLine(sText);

        sText = "ECHO \"^XA^MD0^PRB^JVY^LL1760^LH%XL%,%YL%^FS   \">> COO.TXT";
        s.WriteLine(sText);

        sText = "ECHO \"^FO66,08^BY2,2.0,32^BCN,N,N,N^SN%Sno0%,1,Y^FS   \">> COO.TXT";
        s.WriteLine(sText);

        sText = "ECHO \"^FO66,48^AF,8,8^SN%Sno0%,1,Y^FS     \">> COO.TXT";
        s.WriteLine(sText);

        sText = ":END";
        s.WriteLine(sText);

        sText = "ECHO \"^PQ1     \">> COO.TXT";
        s.WriteLine(sText);

        sText = "ECHO \"^XZ     \">> COO.TXT";
        s.WriteLine(sText);

        sText = "REM MODE COM1 9600"
        s.WriteLine(sText);

        sText = "REM TYPE COO.TXT > COM1"
        s.WriteLine(sText);

        sText = "TYPE COO.TXT > LPT1"
        s.WriteLine(sText);
        s.Close();
    }

}

1 个答案:

答案 0 :(得分:0)

如果您使用的是Windows Vista或更高版本,默认安全设置将阻止您在C:\的根目录上创建文件。

我更改了您的代码以在子文件夹中创建批处理文件,并且它运行良好。此外,更改C:\上的安全权限也是有效的。

编辑:更新的代码将在C:\temp

中创建文件
var sText, s;
var fso = new ActiveXObject("Scripting.FileSystemObject");


if (!fso.FileExists("COO_BTO_Test.bat")) {
    s = fso.CreateTextFile("COO_BTO_Test.bat", true);
    sText = "@echo off";
    s.WriteLine(sText);

    sText = ":Lbl";
    s.WriteLine(sText);

    sText = "ECHO \"^XA^MD0^PRB^JVY^LL1760^LH%XL%,%YL%^FS   \">> COO.TXT";
    s.WriteLine(sText);

    sText = "ECHO \"^FO66,08^BY2,2.0,32^BCN,N,N,N^SN%Sno0%,1,Y^FS   \">> COO.TXT";
    s.WriteLine(sText);

    sText = "ECHO \"^FO66,48^AF,8,8^SN%Sno0%,1,Y^FS     \">> COO.TXT";
    s.WriteLine(sText);

    sText = ":END";
    s.WriteLine(sText);

    sText = "ECHO \"^PQ1     \">> COO.TXT";
    s.WriteLine(sText);

    sText = "ECHO \"^XZ     \">> COO.TXT";
    s.WriteLine(sText);

    sText = "REM MODE COM1 9600"
    s.WriteLine(sText);

    sText = "REM TYPE COO.TXT > COM1"
    s.WriteLine(sText);

    sText = "TYPE COO.TXT > LPT1"
    s.WriteLine(sText);
}