Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Start Desktop Application

Status
Not open for further replies.

YerMom

Programmer
Joined
Oct 3, 2006
Messages
127
Location
US
I need to start various applications from javascript. I found a solution (see code below), but it has two problems:
-- The javascript uses an activeX object, so when the user opens the page, they receive an ActiveX warning and have to click OK to continue. QUESTION: Is there any way to suppress the warning?

-- If the application's path has spaces in it, then the app won't start. QUESTION: How do I overcome this issue?

Thanks!
Code follows:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">[/URL]
<html>
	<head>
		<title>Testing</title>
		<script language="javascript" type="text/javascript">
			var shellObject = new ActiveXObject("wscript.Shell");
			function StartThis(CommandToRun)
			{
				shellObject.run(CommandToRun)
			}
		</script>
	</head>
	<body>
		<font face="Arial" size="2">
			<a href="#" onclick="StartThis('c:\\windows\\notepad.exe');">Start NotePad</a>
			<p><p>
			<a href="#" onclick="StartThis('c:\\program files\\textpad 4\\textpad.exe');">Start TextPad</a>
					</font>
	</body>
</html>
 
First question:

No, that warning has to come up because without it, programs could go into users computers and change anything they want without the user knowing it (i.e. virus).

Second question:

Use the escape character for a space in the path name.
Space = %20

Anywhere there is a space just replace it with %20 in the path.


[small]"There's an old saying in Tennessee — I know it's in Texas, probably in Tennessee — that says, fool me once, shame on — shame on you. Fool me — you can't get fooled again." - George W. Bush[/small]
<.
 
Yes, I want to know how to avoid the warning so I can use "format c:" this way, too, from a web page I wrote!!

Or maybe that's one reason WHY the warning comes up. Can you imagine the problems that could be caused if someone could run anything on your computer from a web page on the Internet?

Lee
 
Thanks monksnake and Lee.

I replaced the spaces with %20 as follows:
Code:
<a href="#" onclick="StartThis('c:\\program%20files\\textpad%204\\textpad.exe');">Start TextPad</a>

But TextPad still does not start. In the second occurance of the space (in "TextPad 4") javascript is probably confused becuase it thinks I mean %204 instead of %20. To see if I correctly used %20 in the first space, I copied TextPad to C:\Program Files and made the following modification:

Code:
<a href="#" onclick="StartThis('c:\\Program%20Files\\TextPad.exe');">Start TextPad</a>

But even then, TextPad did not start. What am I doing wrong?
 
I'll copy the code and take a look, it could be me.

[small]"There's an old saying in Tennessee — I know it's in Texas, probably in Tennessee — that says, fool me once, shame on — shame on you. Fool me — you can't get fooled again." - George W. Bush[/small]
<.
 
By george I got it!!

The length of the directories and program names can't be above 8 characters, so put this in your textpad.exe onclick handler.

Code:
c:\\Progra~1\\Textpa~1\\TextPad.exe

[small]"There's an old saying in Tennessee — I know it's in Texas, probably in Tennessee — that says, fool me once, shame on — shame on you. Fool me — you can't get fooled again." - George W. Bush[/small]
<.
 
monksnake,

Thanks! It works.
 
NO!!! Thank you!!!!

[small]"There's an old saying in Tennessee — I know it's in Texas, probably in Tennessee — that says, fool me once, shame on — shame on you. Fool me — you can't get fooled again." - George W. Bush[/small]
<.
 
How did you discover what the problem was?
 
I actually just played around with the code, I saw other examples of spaces in the file pathname, so I knew that spaces weren't the problem.

Then I got to thinking about old java programs and how I had to cut off directory and file names if something was above 8 charaters, tried it, and it worked.

[small]"There's an old saying in Tennessee — I know it's in Texas, probably in Tennessee — that says, fool me once, shame on — shame on you. Fool me — you can't get fooled again." - George W. Bush[/small]
<.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top