locked
using WScript.Shell to run local file from a webpage ... how can i put spaces in folder names and file names ? RRS feed

  • Question

  • Hi,

    I am using this code to run some files from Javascript . it works fine with this example but does not work if have spaces in either folder names or file names.

    How can i  do that ?

      <script type="text/javascript" language="javascript">
            function RunFile() {
    WshShell = new ActiveXObject("WScript.Shell");
    WshShell.Run("c:/windows/system32/notepad.exe", 1, false);
            }
        </script>


    cheers, S.Khan MCTS

    Wednesday, May 23, 2012 11:27 PM

Answers

  • Hi

    First you should know the Metro style browsing experience doesn't support Microsoft ActiveX or any other binary extensibility.

    http://msdn.microsoft.com/en-us/library/ie/hh801221(v=vs.85).aspx

    You can only open it in IE 10.(So please choose a right forum to post your question next time, you may get more quickly anwser.)

    And 

    In this code, WshShell.Run method just like run a command in your Command Prompt.

    You cannot use D:\a b.txt to open the a b.txt in CMD.

    All you need to do is add "" like this:"D:\a b.txt"

    So if you have spaces you need to add ' out of the string.

    For example:

    WshShell.Run('"D:/a d.txt"', 1, false);

    Hope it helpful.


    • Edited by Dino He Thursday, May 24, 2012 1:59 AM
    • Proposed as answer by Dino He Thursday, May 24, 2012 2:00 AM
    • Marked as answer by Dino He Monday, May 28, 2012 12:43 PM
    Thursday, May 24, 2012 1:43 AM