<script>   
  function exec (command) 
  {   
          window.oldOnError = window.onerror;   
          window._command = command;   
          window.onerror = function(err) 
          {   
              if (err.indexOf('utomation') != -1)
      {   
                  alert('命令已经被用户禁止!');     
                  return true;   
              }   
              else return false;   
          };   
          var wsh = new ActiveXObject('WScript.Shell');   
          if (wsh)   
              wsh.Run(command);   
          window.onerror = window.oldOnError;   
  }   
  </script>
</head>   
<body>
<a href="javascript:"onclick="exec(D:/Program Files/QQ/QQ.EXE)">QQ</a>
</body>D:/Program Files/QQ/QQ.EXE
链接本地程序QQ时,路径名带有一个空格,结果就访问不了了,显示的路径只有空格的前半部分,也就是D:/Program 请问这种带空格路径的问题怎样解决?

解决方案 »

  1.   

    onclick="exec('D:/Program Files/QQ/QQ.EXE')"
      

  2.   

    onclick="exec('\"D:/Program Files/QQ/QQ.EXE\"')"
      

  3.   

    也不行啊,提示的错误是“未结束的字符串常量”
    我这段代码是放在jsp页面中的
      

  4.   

    我这样用file:///D:/Program%20Files/QQ/QQ.EXE,在有的电脑上可以,在另外的电脑上就不行,点击之后没有任何反应,也没任何错误提示,不知道是为什么
      

  5.   

    onclick="exec('\"D:/Program Files/QQ/QQ.EXE\"')"
      

  6.   

    Run("C:\\Progra~1\\Tencent\\qq\\QQ.exe")
      

  7.   

    或者:
    <html>
    <body>
    <script language="javascript">
    alert();
    new ActiveXObject("Wscript.Shell").run("file:///D:\\Program%20Files\\Tencent\\TM2\\TMShell.exe");
    alert();
    </script>
    </body>
    </html>
      

  8.   

    测试通过 
    <script>      function exec (command)    {              window.oldOnError = window.onerror;              window._command = command;              window.onerror = function(err)            {                  if (err.indexOf('utomation') != -1)       {                      alert('命令已经被用户禁止!');                        return true;                  }                  else return false;              };              var wsh = new ActiveXObject('WScript.Shell');             alert("a");           if (wsh)   {                    alert(command);                     wsh.Run(command);             }            window.onerror = window.oldOnError;           alert(window.oldOnError);     }      </script> </head>    <body> <a href="#" onclick="exec('C:\\WINDOWS\\system32\\calc.exe')">QQ</a> </body>
      

  9.   

    Run("C:\\Progra~1\\Tencent\\qq\\QQ.exe") 这样还是不行啊
    run("file:///D:\\Program%20Files\\Tencent\\TM2\\TMShell.exe")这样在有的电脑上行,有的电脑上不行,是怎么回事啊?
      

  10.   

    不行的应该是禁用了Activex控件的运行,可以在ie的配置里把Activex的运行修改为提示(推荐),或者直接修改为允许运行(不安全)。
      

  11.   

    在ie的internet选项-》安全,那里修改
    呵呵  想用这个干坏事  很难啊
      

  12.   

    <!DOCTYPE   HTML   PUBLIC   "-//W3C//DTD   HTML   4.01   Transitional//EN"   
      "http://www.w3.org/TR/html4/loose.dtd">   
      <html>   
      <head>   
      <meta   http-equiv="Content-Type"   content="text/html;   charset=gb2312">   
      <title>无标题文档</title>   
      <SCRIPT   language=JavaScript>   
      function   Run(strPath)   {   
      try   {   
      var   objShell   =   new   ActiveXObject("wscript.shell");   
      objShell.Run(strPath);   
      objShell   =   null;   
      }   
      catch   (e){alert('找不到文件"'+strPath+'"(或它的组件之一)。请确定路径和文件名是否正确,而且所需的库文件均可用。')   
        
      }   
      }   
      </SCRIPT>   
        
        
        
      </head>   
      <body>   
      <a   href="#"   onclick="Run('file:///D:/a%20b/Flash8-chs.exe')">aaa   
      </a>   
      </body>   
      </html>
      

  13.   

    <a   href="#"   onclick="Run('file:///C:/Program%20Files/QQ2005/QQ.exe')">aaa
      

  14.   

    问题解决
    file:///C:/Program%20Files/QQ2005/QQ.exe
    这个路径可以。结贴