Solved

Problem launching program in VBScript ASPX

Posted on 2009-05-08
8
537 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Thoughout my experience working on eCommerce web applications I have seen applications succumbing to increased user demand and throughput. With increased loads the response times started to spike, which leads to user frustration and lost sales. I ha…
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.
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

757 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

17 Experts available now in Live!

Get 1:1 Help Now