Solved

Problem launching program in VBScript ASPX

Posted on 2009-05-08
8
538 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Execute Stored Procedure for a set of values 5 42
Registering DLL 5 43
SQL Login 17 38
Recordset containing single quotes 8 21
      Install BugTracker on Windows 2008 server Step 1:  Install windows 2008 server 32 bit OS and configure IIS. Step 2:  Install SQL server ( SQL server 2005 or SQL server 2005 Express edition. The installer for 2008  version isn’t very f…
If I have to fix slow responding website my first thoughts are server side optimizations: the database may not be optimized or caching is not enabled, or things like that. We often overlook another major part of our web application: the client. We o…
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
This video teaches users how to migrate an existing Wordpress website to a new domain.

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now