无法使用Javascript将参数传递给notepad.exe

时间:2016-07-08 12:22:16

标签: javascript notepad

我正在使用javascript启动notepad.exe并使用以下脚本将参数传递给它。它会启动notepad.exe,但会提示Hello World.txt does not exists. Do you want to create?

传递参数并使用notepad.exe

撰写Hello World的任何想法/建议
function passParam()
{
try{
    //get brwosers details
    var isIE = /*@cc_on!@*/false || !!document.documentMode;

    if(isIE == true)
    {
        var oShell = new ActiveXObject("Shell.Application");

        var filePath = "C:\\Windows";
        var fileName = "notepad.exe";
        var commandParms = "Hello World!";

        oShell.ShellExecute(fileName,commandParms,filePath,"open","1");

        return;
    }
    alert("Please use only IE to launch navigator.");   
}
catch(e){
alert("Error:"+e.message);}
}

1 个答案:

答案 0 :(得分:0)

notepad.exe的命令行参数是要打开的文件名,而不是记事本的初始内容。您必须将文件写入磁盘并打开指向它的记事本。