Solved

Problem launching program in VBScript ASPX

Posted on 2009-05-08
8
540 Views
Last Modified: 2012-05-06
I am just trying to get a simple snippet of code to work for testing purposes, but I'm running into problem after problem.  

I am trying to have a program launch an application installed on the user's computer.  I'm thinking the problem may be that I have RunAt = Server, but not sure what other options I have.

Right now this code parses Ok, and seems to be correct, but whatever application I tell it to run it tells me the file cannot be found, when it is installed on the test system.

Any help would be GREATLY appreciated.
<%@ Page Language="vbscript" Debug="true" %>
 
<SCRIPT LANGUAGE="vbscript" RUNAT="Server">
public sub ButtonClick(sender As Object , e As System.EventArgs) Handles MyButton.Click
	Dim WshShell : WshShell = CreateObject("WScript.Shell")
	Dim strIPAddress
	WshShell.Run("C:\Program Files\Microsoft Office\Office12\WINWORD.exe")
end sub
</script>
 
 
 
 
 
<html>
<head>
<title>Test Launch</title>
</head>
<body bgcolor="white" text="black">
ddd
<form runat="server">
<asp:LinkButton OnClick="ButtonClick" ID="MyButton" Text="click me" Runat="server"> </asp:LinkButton> </body>
</form>
</html>

Open in new window

0
Comment
Question by:thearniec
  • 4
  • 4
8 Comments
 
LVL 12

Expert Comment

by:GuitarRich
ID: 24336408
I'm not sure that code will work. The script tag you have is set to run at the server, so wouldn't it be trying to open the application on the server rather than the client machine?
I would take out the runat="Server" attribute and use the OnClientClick of the link button like this and change the code to client vbscript. I'm still not sure it would work tho as I think there are security issues that would prevent the client script from launching applications on the users machine.

<%@ Page Language="vbscript" Debug="true" %>
<html>
<head>
<title>Test Launch</title>
<script language="vbscript" type="text/vbscript">
 
sub ButtonClick()
    set objShell=CreateObject("Wscript.Shell") 
    objShell.Run("C:\Program Files\Microsoft Office\Office12\WINWORD.exe")
end sub
 
</script>
</head>
<body bgcolor="white" text="black">
ddd
<form runat="server">
<asp:LinkButton OnClientClick="ButtonClick" ID="MyButton" Text="click me" Runat="server"> </asp:LinkButton> </body>
</form>
</html>

Open in new window

0
 

Author Comment

by:thearniec
ID: 24336498
That code is giving me a syntax error that I don't entirely understand...  I use it and it tells me error on line 39.  Of course there aren't 39 lines of code, but I enter debug and see the code snippet below.  Line 39 reads;

<a onclick="ButtonClick;" id="MyButton" href="javascript:__doPostBack('MyButton','')">click me</a> </body>

and it seems to not like the javascript portion there.

ideas?
<html>
<head>
<title>Test Launch</title>
<script language="vbscript" type="text/vbscript">
 
sub ButtonClick()
    set objShell=CreateObject("Wscript.Shell") 
    objShell.Run("C:\Program Files\Microsoft Office\Office12\WINWORD.exe")
end sub
 
</script>
</head>
<body bgcolor="white" text="black">
ddd
<form name="ctl00" method="post" action="test2.aspx" id="ctl00">
<div>
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUJLTU3NTIwMjQ3ZGQGEBaFxjDh55PtZwpDXTOKNlFanw==" />
</div>
 
<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['ctl00'];
if (!theForm) {
    theForm = document.ctl00;
}
function __doPostBack(eventTarget, eventArgument) {
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
    }
}
//]]>
</script>
 
 
<a onclick="ButtonClick;" id="MyButton" href="javascript:__doPostBack('MyButton','')">click me</a> </body>
 
<div>
 
	<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAgKigs2zCAK4ookeufULrdoqWFPiDwqGstDn1iTUfNo=" />
</div></form>
</html>

Open in new window

0
 
LVL 12

Expert Comment

by:GuitarRich
ID: 24336533
It doesn't like the asp linkbutton - just change it to a standard anchor tag like this:
<asp:LinkButton OnClick="ButtonClick" ID="MyButton" Text="click me" Runat="server"> </asp:LinkButton> </body>
 
changes to:
 
<a onclick="ButtonClick()">click me</a>

Open in new window

0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:thearniec
ID: 24336586
That fixed the syntax error, but now getting "unknown error" on

objShell.Run("C:\Program Files\Microsoft Office\Office12\WINWORD.exe")

It's not the "File not found" error as before, nor is it a security warning...
0
 
LVL 12

Expert Comment

by:GuitarRich
ID: 24336687
try saving the lines:
    set objShell=CreateObject("Wscript.Shell")
    objShell.Run("C:\Program Files\Microsoft Office\Office12\WINWORD.exe")

to a file called test.vbs on your hard disk and run that by double clicking it. If Word runs ok I would suggest it is a security issue. When I try the site I get an error creating the Wscript.Shell object. but it works ok in a VBS file.
0
 

Author Comment

by:thearniec
ID: 24336725
Gah...nope.  Says "Can't find the file specified"  But I know the path is right, if I copy and paste the C:\Program files...\Winword.exe into the Start, Run box, loads up fine.
0
 
LVL 12

Accepted Solution

by:
GuitarRich earned 500 total points
ID: 24336785
if you change the path to just say notepad does that work?
0
 

Author Comment

by:thearniec
ID: 24336940
Ah you set me on the right path.  

Yes.  Even in the web page.  Making it

 objShell.Run("notepad.exe")

works.  So I started researching the \s and the spaces, and THIS made word launch:

    objShell.Run("""C:\\Program Files\\Microsoft Office\\Office12\\winword.exe""")


THANK YOU!

0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A Change in PHP Behavior with Session Write Short Circuit (http://php.net/manual/en/book.session.php#116217) (Winter 2014)** With the release of PHP 5.6 the session handler changed in a way that many think should be considered a bug.  See the note …
It’s a strangely common occurrence that when you send someone their login details for a system, they can’t get in. This article will help you understand why it happens, and what you can do about it.
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question