Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-31-2007, 03:48 PM   PM User | #1
jleone
Regular Coder

 
Join Date: Jan 2007
Posts: 117
Thanks: 4
Thanked 2 Times in 2 Posts
jleone is an unknown quantity at this point
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>
jleone is offline   Reply With Quote
Old 01-31-2007, 04:15 PM   PM User | #2
jleone
Regular Coder

 
Join Date: Jan 2007
Posts: 117
Thanks: 4
Thanked 2 Times in 2 Posts
jleone is an unknown quantity at this point
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.
jleone is offline   Reply With Quote
Old 01-31-2007, 04:17 PM   PM User | #3
jleone
Regular Coder

 
Join Date: Jan 2007
Posts: 117
Thanks: 4
Thanked 2 Times in 2 Posts
jleone is an unknown quantity at this point
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>
jleone is offline   Reply With Quote
Old 01-31-2007, 04:29 PM   PM User | #4
jleone
Regular Coder

 
Join Date: Jan 2007
Posts: 117
Thanks: 4
Thanked 2 Times in 2 Posts
jleone is an unknown quantity at this point
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).
jleone is offline   Reply With Quote
Old 01-31-2007, 05:11 PM   PM User | #5
tonyp12
New Coder

 
Join Date: Jan 2007
Posts: 93
Thanks: 0
Thanked 0 Times in 0 Posts
tonyp12 has a little shameless behaviour in the past
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..
tonyp12 is offline   Reply With Quote
Old 01-31-2007, 05:16 PM   PM User | #6
jleone
Regular Coder

 
Join Date: Jan 2007
Posts: 117
Thanks: 4
Thanked 2 Times in 2 Posts
jleone is an unknown quantity at this point
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>
jleone is offline   Reply With Quote
Old 01-31-2007, 05:20 PM   PM User | #7
tonyp12
New Coder

 
Join Date: Jan 2007
Posts: 93
Thanks: 0
Thanked 0 Times in 0 Posts
tonyp12 has a little shameless behaviour in the past
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..
tonyp12 is offline   Reply With Quote
Old 01-31-2007, 05:23 PM   PM User | #8
jleone
Regular Coder

 
Join Date: Jan 2007
Posts: 117
Thanks: 4
Thanked 2 Times in 2 Posts
jleone is an unknown quantity at this point
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.
jleone is offline   Reply With Quote
Old 01-31-2007, 05:25 PM   PM User | #9
jleone
Regular Coder

 
Join Date: Jan 2007
Posts: 117
Thanks: 4
Thanked 2 Times in 2 Posts
jleone is an unknown quantity at this point
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.
jleone is offline   Reply With Quote
Old 01-31-2007, 05:37 PM   PM User | #10
tonyp12
New Coder

 
Join Date: Jan 2007
Posts: 93
Thanks: 0
Thanked 0 Times in 0 Posts
tonyp12 has a little shameless behaviour in the past
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..
tonyp12 is offline   Reply With Quote
Old 01-31-2007, 05:47 PM   PM User | #11
jleone
Regular Coder

 
Join Date: Jan 2007
Posts: 117
Thanks: 4
Thanked 2 Times in 2 Posts
jleone is an unknown quantity at this point
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.
jleone is offline   Reply With Quote
Old 01-31-2007, 05:49 PM   PM User | #12
david_kw
Senior Coder

 
Join Date: Nov 2006
Posts: 1,000
Thanks: 0
Thanked 0 Times in 0 Posts
david_kw will become famous soon enough
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
david_kw is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:00 PM.


Advertisement
Log in to turn off these ads.