Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: launching a MS window that runs a .exe

104 views
Skip to first unread message

VK

unread,
Dec 8, 2006, 11:59:25 AM12/8/06
to

Pete wrote:
> What I'm looking for is a way of just running any arbitrary .exe file.
> Does anyone know of a way to do this?
>
> One of the replies to the original poster stated that it could be done
> with an activex control, but I've searched and haven't been able to find
> one. Was the poster just saying that technically it would be possible,
> rather than that someone had actually done it and here's the link to or
> name of the control?

A few notes (see the source at the bottom):

1) obviously the script will not work (will show "Security exception"
alert) within the default sandbox.

2) a phychological drawback of it is that IE's end users in your
company may get accustomed to see security warning dialog AND press Yes
in it (while the mantra should be "simply say no"). Thus it is highly
suggested to eliminate the security warning step by adjusting intranet
settings.

3) if you are copying the source over Google Groups be aware that
Google james strings with at-sign in it (must be an e-mail protection
mesure?). In the particular the string:
Components.classes['@mozilla.org/file/local;1']
has to be
Components.classes['at-sign and the rest

4) this script works for IE 5.0 or higher and for any Gecko-based
browser (including Firefox of course).

5) Don't forget that backslash in Windows path is the escape character
in JavaScript: so always double it: c:\\windows\\notepad.exe

6) Enjoy! :-)


<html>
<head>
<title>Exe</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<script type="text/javascript">
/*
Copyright (c) 2005 VK [schools_ring_at_yahoo.com]
Permission is hereby granted, free of charge, to any person obtaining
a copy
of this software and associated documentation files (the "Software"),

to deal in the Software without restriction, including without
limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or
sell copies of the Software, and to permit persons to whom the
Software is furnished
to do so, subject to the following conditions:</p>
The above copyright notice and this permission notice shall be
included in
all copies or substantial portions of the Software.</p>
THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY
KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY

CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

var Shell = {
'$err' : function(m) {
var msg = m || 'Security exception';
window.alert('[Shell] script object\n\n' + msg);
}
, 'MSIE' : ( (typeof window != 'undefined')
&& (typeof window.ActiveXObject != 'undefined'))
, 'Gecko' : ( (typeof window != 'undefined')
&& (typeof window.netscape != 'undefined')
&& (typeof window.netscape.security != 'undefined')
/* that Opera... always pretending to do everything
* everywhere but not really doing anything of it...
*/
&& (typeof window.opera != 'object'))
, 'run' : function(path) {
if ((typeof path == 'string') && (path != '')) {
if ((Shell.MSIE) && (typeof Shell.$ == 'undefined')) {
try {Shell.$ = new ActiveXObject('WScript.Shell');}
catch(e) {Shell.$err(e.message);}
}
if (Shell.MSIE) {
try {Shell.$.Run(path);}
catch(e) {Shell.$err(e.message);}
}
else if (Shell.Gecko) {
/* Netscape security model grants privileges
* on the per-call per-context basis; thus
* privilege request and privilege usage
* have to be in the same block.
*/
try {
netscape.security.PrivilegeManager.
enablePrivilege('UniversalXPConnect');
Shell.$ = Components.classes['@mozilla.org/file/local;1'].
createInstance(Components.interfaces.nsILocalFile);
/* NOTE: initWithPath has problems on MacOS and other OSes
* which do not represent file locations as paths.
* If you do use this function, be very aware of this problem!
*/
Shell.$.initWithPath(path);
Shell.$.launch();
}
catch(e) {
Shell.$err(e.message);
}
}
else {
Shell.$err('not supported on this platform');
}
}
else {
Shell.$err('Invalid argument');
}
}
};
</script>
</head>
<body>
<p>
<a
href="javascript:void(Shell.run('c:\\windows\\notepad.exe'));">Launch
Notepad</a>
</p>
</body>
</html>

0 new messages