Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    Regular Coder
    Join Date
    Jan 2007
    Posts
    117
    Thanks
    4
    Thanked 2 Times in 2 Posts

    WScript.Shell problem

    Hi guys -

    Trying to open a file on a network drive when user clicks an HTML button on a web page. When page loads, there is an error that states there's an invalid character on the line where I declare my variable. When I click the button, the error changes to "Object expected" but is on a line nowhere near any scripting or any HTML code related to scripting. Does my code look correct or no?

    And, yes my button is calling the function on the "onclick" and "filepath" from VB code does have a value when I do a view source on the page.

    <script language="javascript" type="text/javascript">
    function OpenFile(){
    var x = new ActiveXObject("WScript.Shell");
    x.run(<%=filepath %>);
    }
    </script>

  • #2
    Regular Coder
    Join Date
    Jan 2007
    Posts
    117
    Thanks
    4
    Thanked 2 Times in 2 Posts
    OK, I found out the reason for the invalid character error on the page load. It doesn't like the "filepath" from the VB side. I replaced with a text string to my local hard drive and the error goes away.

    When I click the button now, the error is: "The system cannot find the file specified" even though the file exists.

  • #3
    Regular Coder
    Join Date
    Jan 2007
    Posts
    117
    Thanks
    4
    Thanked 2 Times in 2 Posts
    Sorry, here's what the code looks like now. I have tried with and without the "file://" and both forward and back slashes with no luck.

    <script language="javascript" type="text/javascript">
    function OpenFile(){
    var x = new ActiveXObject("WScript.Shell");
    x.run("file://C:/Temp/123.jpg");
    }
    </script>

  • #4
    Regular Coder
    Join Date
    Jan 2007
    Posts
    117
    Thanks
    4
    Thanked 2 Times in 2 Posts
    OK, I can open executables if I replace with file string say with "notepad.exe" or "winword.exe".

    Are executables all that I can open with WScript.Shell? I am trying to open image files (jpg,bmp,tif).

  • #5
    New Coder
    Join Date
    Jan 2007
    Posts
    93
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You can not really just "open" a image.
    But you want it to open the image with the program that is the default for that extension (.jpg or .gif etc)?


    And you should add a 1 (or the other options available)
    x.run("file://C:/Temp/123.jpg",1 );


    If you want to open it with Windows Picture and Fax viewer

    rundll32.exe %SystemRoot%\system32\shimgvw.dll,ImageView_Fullscreen path-to-picture
    Last edited by tonyp12; 01-31-2007 at 05:17 PM.

  • #6
    Regular Coder
    Join Date
    Jan 2007
    Posts
    117
    Thanks
    4
    Thanked 2 Times in 2 Posts
    Yes, that is what I meant by opening (to open the file with the default program it is assigned to be opened with).

    I still have the same problem. Error is "The system cannot find the path specified". Here is my code after your suggestion.

    <script language="javascript" type="text/javascript">
    function OpenFile(){
    var x = new ActiveXObject("WScript.Shell");
    x.Run("file://C:/Temp/123.jpg",1);
    }
    </script>

  • #7
    New Coder
    Join Date
    Jan 2007
    Posts
    93
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Did you try without the 'file://' ?
    and I don't think the path to Temp starts with just C:\
    Last edited by tonyp12; 01-31-2007 at 05:24 PM.

  • #8
    Regular Coder
    Join Date
    Jan 2007
    Posts
    117
    Thanks
    4
    Thanked 2 Times in 2 Posts
    Yes, same result. The one big question, though, is will this work when trying to get a file from a network drive? If not, I might as well stop while I am ahead if I can only get it to work from a local hard drive.

  • #9
    Regular Coder
    Join Date
    Jan 2007
    Posts
    117
    Thanks
    4
    Thanked 2 Times in 2 Posts
    OK, now the code works if I try to open a .txt file in NotePad from local hard drive. It doesn't like image files.

  • #10
    New Coder
    Join Date
    Jan 2007
    Posts
    93
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If I try to type this in from a cmd window it does not work.

    C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Sunset.jpg

    But this works
    "C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Sunset.jpg"

    So it does not like spaces in folder names.

    This works: (single ' in front of ")
    oShell.run ('"C:\\Documents and Settings\\All Users\\Documents\\My Pictures\\Sample Pictures\\Sunset.jpg"',1);
    Last edited by tonyp12; 01-31-2007 at 05:58 PM.

  • #11
    Regular Coder
    Join Date
    Jan 2007
    Posts
    117
    Thanks
    4
    Thanked 2 Times in 2 Posts
    Spoke with my supervisor. After I told him the problem, he suggested a different route. I am going to try it and see if I can get it to work. Thanks for your help. I'll reply later on if I come up with a solution.

  • #12
    Senior Coder
    Join Date
    Nov 2006
    Posts
    1,000
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This worked for me.

    Code:
    <html>
      <head>
        <title>Run Pic</title>
        <script type="text/javascript">
          function doIt() {
            var sh = new ActiveXObject("WScript.Shell");
            var s = sh.run("file://c:/inetpub/wwwroot/junque/images/pizza.jpg", 1);
            var adiv = document.getElementById("adiv");
            adiv.innerHTML = s;
          }
        </script>
      </head>
      <body>
        <div>
          <button onclick="doIt();">Do it</button>
          <br />
          <div id="adiv"> </div>
        </div>
      </body>
    </html>
    david_kw


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •