0

我有应该在我的 c:\ 上创建批处理文件的代码。它应该在我的按钮的 onclientclick 上创建它。当我单击按钮时,它不会在该位置创建文件。我缺少代码吗?

 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();
    }

}
4

1 回答 1

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);
}
于 2013-06-12T19:39:15.457 回答