How to call an windows program with ActiveXObject and load a file aswell?

D

DL

The following code to launch Windows Paint program with an image file
failed. The problem seems related to the location of the image file
under the Program Files folder (for the white space between the two
words).

<script language="JScript">
function runPaint(f) {
prog = "mspaint.exe C:\\'Program Files'\\myProgram\\myImageFiles'+f;
WSH = new ActiveXObject("WScript.Shell");
WSH.run(prog);
}
</script>

Had the image file located in a folder without spaces, say, Paint,
then, the following code would work,
<script language="JScript">
function runPaint(f) {
prog = "mspaint.exe C:\\Paint\\myImageFiles'+f;
WSH = new ActiveXObject("WScript.Shell");
WSH.run(prog);
}
</script>

I can't change the image location, how to escape the white space? how
to solve it?

Thanks.
 
D

Don84

         ^                                                        ^
I think these need to be both double quotes


         ^                                   ^
Same here?

Paul

Sorry, it were double quoted. Somehow the copy/paste got messed up,
it were like the following:

prog = "mspaint.exe C:\\'Program Files'\\myProgram\\myImageFiles"+f;
 
D

Don84

Sorry, it were double quoted.  Somehow the copy/paste got messed up,
it were like the following:

prog = "mspaint.exe C:\\'Program Files'\\myProgram\\myImageFiles"+f;

Just thought of old DOS 8.2 convention, tried the following instead,
prog = "mspaint.exe C:\\Progra~1\\myProgram\\myImageFiles"+f;

it works with IE7 on XP SP3 but not Firefox 3.0.11 on the same
machine. so, it's only half good.
 
G

Greg Russell

In DL <[email protected]> typed:

....
prog = "mspaint.exe C:\\'Program Files'\\myProgram\\myImageFiles'+f; ....
I can't change the image location, how to escape the white space?
....

Quote and backslash problems:

prog = "mspaint.exe 'C:\\Program Files\myProgram\myImageFiles\'"+f;
 
S

Stevo

Don84 said:
Just thought of old DOS 8.2 convention, tried the following instead,
prog = "mspaint.exe C:\\Progra~1\\myProgram\\myImageFiles"+f;

it works with IE7 on XP SP3 but not Firefox 3.0.11 on the same
machine. so, it's only half good.

It's actually called DOS 8.3 convention, but you can avoid that by using
%20 instead of spaces. So this would work on IE:

prog = "mspaint.exe C:\\Program%20Files\\myProgram\\myImageFiles"+f;

All non-IE browsers (that I know of) prefer a different format though.
Instead of C:\\ and backslashes throughout, you'd want file:///c:/ and
forward slashes throughout.

Finding your perfect string to use is easy. Just put an image into your
desired folder, and then drag/drop it onto Firefox. You'll see in the
address bar a URL like this:

file:///C:/Program%20Files/some%20folder/deleteme.gif

The good news is that IE will accept that URL also.

Warning #1

Putting images in the program files folder is a bad idea. I believe
Vista won't let mspaint save them there. It's been a "best practice" for
a long time, going back to the old Petzold books for Windows programmers
to not write anything into the program files folder. Only the installer
should write there. For already installed programs that want to store
data, they should use the local settings application data folders
instead. When Vista came along, instead of that just being a recommended
practice, it became enforced. This was one of the big reasons that a lot
of software needed updating for Vista.

Warning #2

The folder named "Program Files" is a localized name. In other languages
it's called something else - usually the foreign translation of one or
both of those english words.
 
D

Don84

It's actually called DOS 8.3 convention, but you can avoid that by using
%20 instead of spaces. So this would work on IE:

prog = "mspaint.exe C:\\Program%20Files\\myProgram\\myImageFiles"+f;

All non-IE browsers (that I know of) prefer a different format though.
Instead of C:\\ and backslashes throughout, you'd want file:///c:/ and
forward slashes throughout.

Finding your perfect string to use is easy. Just put an image into your
desired folder, and then drag/drop it onto Firefox. You'll see in the
address bar a URL like this:

file:///C:/Program%20Files/some%20folder/deleteme.gif

The good news is that IE will accept that URL also.

Warning #1

Putting images in the program files folder is a bad idea. I believe
Vista won't let mspaint save them there. It's been a "best practice" for
a long time, going back to the old Petzold books for Windows programmers
to not write anything into the program files folder. Only the installer
should write there. For already installed programs that want to store
data, they should use the local settings application data folders
instead. When Vista came along, instead of that just being a recommended
practice, it became enforced. This was one of the big reasons that a lot
of software needed updating for Vista.

Warning #2

The folder named "Program Files" is a localized name. In other languages
it's called something else - usually the foreign translation of one or
both of those english words.- Hide quoted text -

- Show quoted text -

Sorry,
prog = "mspaint.exe C:\\Program%20Files\\myProgram\\myImageFiles"+f;

did not work for neither IE7 nor Firefox 3.0.11.

On DOS convention, possibly my typo, 8.3 or my post has been hijacked.
On not placing images into "Program Files" folder, I'm with you,
however, the images are associated with a given program under "PF" ...

Thanks though.
 
D

Don84

InDL <[email protected]> typed:

...> prog = "mspaint.exe C:\\'Program Files'\\myProgram\\myImageFiles'+f;
...

...

Quote and backslash problems:

prog = "mspaint.exe 'C:\\Program Files\myProgram\myImageFiles\'"+f;

Sorry it didn't work with IE7 nor Firefox 3.0.11. Could it because I
have two anti-virus programs up and running? but then with the same
security setting the Progra~1 worked with IE7 ...
 
R

Richard Cornford

On Jun 30, 10:09 pm, Greg Russell wrote:
^
Sorry it didn't work with IE7 nor Firefox 3.0.11.

At least one good reason for that not working is the positioning of
the final apostrophise. Windows would like to see them (or double
quotes) around the entire file path, but the final apostrophe is
inserted before whatever is added to the string by concatenating the -
f - value.

A second reason is going to be the backslashes. Backslashes may be
file path separators in Windows but they are escape characters in
javascript string literals. A single backslash in a string literal
will not appear in the resulting string, instead it acts in
conjunction with following characters to form 'escape sequences'. For
example, "\t" results in a string containing the tab character, and
"\m" results in a string containing the lower case M character
(because there is no special meaning to "\m"). To get a backslash into
the resulting string (which is going to be (nearly) essential in a
Windows file path) the backslash has to be escaped, by substituting it
with one of "\\", "\u005C" or "\x5C", which are the three possible
'escape sequences' for the backslash character.
Could it because I have two anti-virus programs up and running?
Unlikely.

but then with the same security setting the Progra~1 worked with
IE7 ...

You do realise that instantiating WScript objects is only feasible in
a reduced security context (so not on the public internet)?

Richard.
 
R

Richard Cornford

On Jul 1, 3:56 pm, Don84 wrote:
prog = "mspaint.exe C:\\Program%20Files\\myProgram\\myImageFiles"+f;

did not work for neither IE7 nor Firefox 3.0.11.
<snip>

No it wouldn't. URI encoding is (mostly) only appropriate with/in
URIs, it is not going to mean much in a Windows file path.

Incidentally, how exactly do you propose creating the wscript object
in Firefox?

Richard.
 
D

Don84

On Jul 1, 3:56 pm, Don84 wrote:


<snip>

No it wouldn't. URI encoding is (mostly) only appropriate with/in
URIs, it is not going to mean much in a Windows file path.

Incidentally, how exactly do you propose creating the wscript object
in Firefox?

Richard.

Yes, I understand the security ramification of the ActiveXObject call,
it's local and offline use.
 
R

Richard Cornford

On Jul 1, 11:20 am, Richard Cornford wrote:
Yes, I understand the security ramification of the ActiveXObject
call, it's local and offline use.

Security aside, Firefox does not even have the ActiveXObject
constructor (unless they have added it very recently). So when you say
that you cannot get this to work in Firefox, seeing the code you have
posted, that would be the expected outcome; the call to the
ActiveXObject constructor would error, terminating the execution of
the function.

Richard.
 
D

Don84

Security aside, Firefox does not even have the ActiveXObject
constructor (unless they have added it very recently). So when you say
that you cannot get this to work in Firefox, seeing the code you have
posted, that would be the expected outcome; the call to the
ActiveXObject constructor would error, terminating the execution of
the function.

Richard.

ok, thanks, I thought ActiveXObject belongs to Windows not IE but it
looks like I was wrong.
 
T

Thomas 'PointedEars' Lahn

Richard said:
Yes, I understand the security ramification of the ActiveXObject
call, it's local and offline use.

Security aside, Firefox does not even have the ActiveXObject
constructor (unless they have added it very recently). [...]

Depends. There is an ActiveX plugin for Gecko-based UAs but it appears
development of it has stopped years ago and I don't know if it still works
(security aside, as you have said).

<http://www.iol.ie/~locka/mozilla/control.htm>

There is also the IE Tab extension which can be configured so that, on
Windows, the MSHTML ActiveX/COM control is used for rendering on
user-defined Web sites (uses regular expression matching on the URI). In
particular, this is how I made the Foxit Reader plugin work with Firefox on
my office desktop (I don't remember if their new Firefox plugin had the same
functionality. You certainly don't want to use the Adobe Reader plugin with
Firefox because AFAICS it continues running and in the process eats up free
memory like candy -- until there is no more.)

<https://addons.mozilla.org/firefox/addon/1419>


PointedEars
 
D

Don84

Security aside, Firefox does not even have the ActiveXObject
constructor (unless they have added it very recently). [...]

Depends.  There is an ActiveX plugin for Gecko-based UAs but it appears
development of it has stopped years ago and I don't know if it still works
(security aside, as you have said).

<http://www.iol.ie/~locka/mozilla/control.htm>

There is also the IE Tab extension which can be configured so that, on
Windows, the MSHTML ActiveX/COM control is used for rendering on
user-defined Web sites (uses regular expression matching on the URI).  In
particular, this is how I made the Foxit Reader plugin work with Firefox on
my office desktop (I don't remember if their new Firefox plugin had the same
functionality.  You certainly don't want to use the Adobe Reader pluginwith
Firefox because AFAICS it continues running and in the process eats up free
memory like candy -- until there is no more.)

<https://addons.mozilla.org/firefox/addon/1419>

PointedEars

I thought of a simpler solution, that is, if online is detected, the
option(button) of using ActiveXObject is simply disabled. As for
Firefox users, yes, either advise them to add IE Tab add-on or simply
use IE just for this app, why can't one be flexible?
 
D

Dr J R Stockton

In comp.lang.javascript message said:
Warning #2

The folder named "Program Files" is a localized name. In other
languages it's called something else - usually the foreign translation
of one or both of those english words.

In my WinXP systems, the environment variables "ProgramFiles" have the
value "C:\Program Files".

A JavaScript system which can execute arbitrary code should be able to
read the environment, if necessary by executing CMD.EXE with suitable
arguments.

In non-English systems the name of the variable may still be
"ProgramFiles".

Otherwise, scan the environment for a plausible entry.

IMHO, translating an operating system without translating programming
languages or providing a dictionary is silly.

I once looked (in Blackwell's) at a manual for French Algol, with
reserved words apparently having been translated by one ignorant of the
difference between an infinitive and an imperative.
 
T

Thomas 'PointedEars' Lahn

Don84 said:
Thomas said:
Richard said:
Security aside, Firefox does not even have the ActiveXObject
constructor (unless they have added it very recently). [...]
Depends. There is an ActiveX plugin for Gecko-based UAs but it appears
development of it has stopped years ago and I don't know if it still works
(security aside, as you have said).

<http://www.iol.ie/~locka/mozilla/control.htm>

There is also the IE Tab extension which can be configured so that, on
Windows, the MSHTML ActiveX/COM control is used for rendering on
user-defined Web sites (uses regular expression matching on the URI). In
particular, this is how I made the Foxit Reader plugin work with Firefox on
my office desktop (I don't remember if their new Firefox plugin had the same
functionality. You certainly don't want to use the Adobe Reader plugin with
Firefox because AFAICS it continues running and in the process eats up free
memory like candy -- until there is no more.)

<https://addons.mozilla.org/firefox/addon/1419>
[...]

I thought of a simpler solution, that is, if online is detected, the
option(button) of using ActiveXObject is simply disabled.

And how do you propose to detect that without an ActiveX/COM control?
As for Firefox users, yes, either advise them to add IE Tab add-on
or simply use IE just for this app, why can't one be flexible?

IE Tab only works on Windows because (IE 5/Mac aside) IE/MSHTML only works
on Windows natively. By contrast, Firefox/Gecko works almost everywhere.
That's why.

Learn to quote.


Score adjusted

PointedEars
 
D

Don84

Don84 said:
Thomas said:
Richard Cornford wrote:
Security aside, Firefox does not even have the ActiveXObject
constructor (unless they have added it very recently). [...]
Depends.  There is an ActiveX plugin for Gecko-based UAs but it appears
development of it has stopped years ago and I don't know if it still works
(security aside, as you have said).
<http://www.iol.ie/~locka/mozilla/control.htm>
There is also the IE Tab extension which can be configured so that, on
Windows, the MSHTML ActiveX/COM control is used for rendering on
user-defined Web sites (uses regular expression matching on the URI).  In
particular, this is how I made the Foxit Reader plugin work with Firefox on
my office desktop (I don't remember if their new Firefox plugin had the same
functionality.  You certainly don't want to use the Adobe Reader plugin with
Firefox because AFAICS it continues running and in the process eats upfree
memory like candy -- until there is no more.)
<https://addons.mozilla.org/firefox/addon/1419>
[...]
I thought of a simpler solution, that is, if online is detected, the
option(button) of using ActiveXObject is simply disabled.

And how do you propose to detect that without an ActiveX/COM control?

an http call.
IE Tab only works on Windows because (IE 5/Mac aside) IE/MSHTML only works
on Windows natively.  By contrast, Firefox/Gecko works almost everywhere.
That's why.

Sorry, info provided were not sufficient. It's Windows only and no, I
don't want to get into the fight of why not supporting all, it's not a
public web site or app for that matter.
 
D

Don84

In comp.lang.javascript message <[email protected]>,
Wed, 1 Jul 2009 08:55:33, Stevo <[email protected]> posted:





In my WinXP systems, the environment variables "ProgramFiles" have the
value "C:\Program Files".

A JavaScript system  which can execute arbitrary code should be able to
read the environment, if necessary by executing CMD.EXE with suitable
arguments.

In non-English systems the name of the variable may still be
"ProgramFiles".

Otherwise, scan the environment for a plausible entry.

IMHO, translating an operating system without translating programming
languages or providing a dictionary is silly.

I once looked (in Blackwell's) at a manual for French Algol, with
reserved words apparently having been translated by one ignorant of the
difference between an infinitive and an imperative.

--
 (c) John Stockton, nr London UK.  [email protected]  DOS 3.36.20 ; WinXP.
 Web  <URL:http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms& links.
 PAS EXE TXT ZIP via  <URL:http://www.merlyn.demon.co.uk/programs/00index.htm>
 My DOS  <URL:http://www.merlyn.demon.co.uk/batfiles.htm> - also batprogs.htm.

Sorry, the DOS/NT var of %programfiles% did not work for me, English
OS. Also, I didn't find such a var when I start a DOS session to
check it out. So, probably it's not available across board even for
Windows, at least, XP, since I tried it with my XP sp3.
 
D

David Mark

Sorry, the DOS/NT var of %programfiles% did not work for me, English
OS.  Also, I didn't find such a var when I start a DOS session to
check it out.  So, probably it's not available across board even for
Windows, at least, XP, since I tried it with my XP sp3.

As far as I can remember, you have to get that with an API call (and
are those some bad memories.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top