WsShell.运行don't accept变量(例如T1)作为Argument或Parameter

本文关键字:T1 例如 作为 Argument Parameter 变量 don 运行 accept WsShell | 更新日期: 2023-09-27 17:50:52

下面两个c#程序Test1 &Test2一个工作,一个不工作,如果有人知道为什么,请帮助。

// Not Working X    
    protected void Test1(object sender, EventArgs e)
    {
        string T1;
        T1 = "winword.exe c:/sql_pt_c/mydocx.docx";
        string javaScript =
            "<script language=JavaScript>'n" +
            "WshShell = new ActiveXObject('WScript.Shell');'n" +
            "WshShell.Run(T1, 1, true);'n" +
            "</script>";
        RegisterStartupScript("", javaScript);
    }

// Working v/
    protected void Test1(object sender, EventArgs e)
    {
        string javaScript =
            "<script language=JavaScript>'n" +
            "WshShell = new ActiveXObject('WScript.Shell');'n" +
            "WshShell.Run('winword.exe c:/sql_pt_c/mydocx.docx', 1, true);'n" +
            "</script>";
        RegisterStartupScript("", javaScript);
    }

WsShell.运行don't accept变量(例如T1)作为Argument或Parameter

我认为你需要连接T1

string T1 = "winword.exe c:/sql_pt_c/mydocx.docx";
string javaScript =
        "<script language=JavaScript>'n" +
        "WshShell = new ActiveXObject('WScript.Shell');'n" +
        "WshShell.Run('"+T1+"', 1, true);'n" +
        "</script>";

现在,您包含了字面值字符串"T1",而不是变量

的值。
相关文章: