...

View Full Version : WScript.Shell problem



jleone
01-31-2007, 04:48 PM
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
01-31-2007, 05:15 PM
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
01-31-2007, 05:17 PM
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
01-31-2007, 05:29 PM
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).

tonyp12
01-31-2007, 06:11 PM
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

jleone
01-31-2007, 06:16 PM
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>

tonyp12
01-31-2007, 06:20 PM
Did you try without the 'file://' ?
and I don't think the path to Temp starts with just C:\

jleone
01-31-2007, 06:23 PM
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
01-31-2007, 06:25 PM
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.

tonyp12
01-31-2007, 06:37 PM
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);

jleone
01-31-2007, 06:47 PM
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.

david_kw
01-31-2007, 06:49 PM
This worked for me.



<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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum