.vbs to ASP page

T

tianung

How do I convert a .vbs script into an ASP page on the web ?

For illustration, let's say the .vbs file is "test.vbs" which contains
only one line of code:

MsgBox "Hello World !"


Do I simply create the text:

<%
MsgBox "Hello World !"
%>

and save the file as "test.asp" ? Should there be any other lines of
code apart from this ?

I've just subscribe to an "ASP host" called "x10hosting.com" - can I
simply place this "test.asp" file in the default folder (via FTP) and
link to it via Internet Explorer (version 6 still for me) ?

I tried doing this but all I got to see on Internet Explorer was the
actual script text (the script was not executed). Someone told me I
need to "enable mono" but I've no idea what this means - would
everybody trying to execute this "test.asp" have to "enable mono" on
their PC's as well ?

Just a beginner as you can see. Please help !
 
B

Bob Barrows

tianung said:
How do I convert a .vbs script into an ASP page on the web ?

For illustration, let's say the .vbs file is "test.vbs" which contains
only one line of code:

MsgBox "Hello World !"


Do I simply create the text:

<%
MsgBox "Hello World !"
%>

No. MsgBox will display the message on the server (ASP code is executed on
the server), so never use things like MsgBox ir Inputbox in server-side
code.

You need to think of it this way: ASP generates html to be sent to the
client using the Response object. The html is rendered by the browser and
the result is displayed to the user.

The ASP-equivalent hello-world script would be this:

<%
Response.Write "Hello World !"
%>

There are 5 main objects intrinsically available to ASP script: Request,
Response, Session, Application and Server. You can read more about them
here:
http://msdn.microsoft.com/en-us/library/ms524664.aspx
and save the file as "test.asp" ? Should there be any other lines of
code apart from this ?

No other lines of code are required. As long as the server is set up to
correctly process .asp files, that should be all you need.
I've just subscribe to an "ASP host" called "x10hosting.com" - can I
simply place this "test.asp" file in the default folder (via FTP) and
link to it via Internet Explorer (version 6 still for me) ?

If you mean "the default folder that the host has assigned to you", then
yes, as long as the folder resides within the wwwroot folder (or is mapped
to a virtual IIS drectory) and the host has correctly configured IIS and the
directory to process .asp files using the asp.dll (this is assuming the host
is using IIS - it is possible to run ASP with an apache web server, but it
requires additional software such as Chilisoft).
I tried doing this but all I got to see on Internet Explorer was the
actual script text (the script was not executed). Someone told me I
need to "enable mono"

I've never heard of that. I suspect you need to get some support from your
host, because there are configurations (extension-mapping, enabling ASP,
etc.) that only the host can make unless he has provided tools to enable you
to do it.
 
F

Family Tree Mike

tianung said:
I tried doing this but all I got to see on Internet Explorer was the
actual script text (the script was not executed). Someone told me I
need to "enable mono" but I've no idea what this means - would
everybody trying to execute this "test.asp" have to "enable mono" on
their PC's as well ?

Mono is the publicly available version of the Microsoft.Net framework.
It is commonly used to run .Net programs on non-windows machines. This
would not appear to apply in your situation.
 
T

tianung

No. MsgBox will display the message on the server (ASP code is executed on
the server), so never use things like MsgBox ir Inputbox in server-side
code.

Thanks very much Bob. You've pointed out a fundamental concept. Just
so I don't bark up the wrong tree - would the following VB script that
opens an Excel spreadsheet on the user's PC be easily translatable to
an ASP page on the web ? Or would it similarly attempt to open on the
server side ?

Dim xlApp
Set xlApp = CreateObject("Excel.Application")
xlApp.DisplayAlerts = False
On Error Resume Next
Set oWorkbook = xlApp.Workbooks.Open("http://xxxxx.com/
MySpreadsheet.xls")
If Err.Number <> 0 Then WScript.Quit
xlApp.Visible = True
oWorkbook.Activate
xlApp.WindowState = 3
Set xlApp = Nothing

As you can see, the above VB script opens the Excel spreadsheet
(stored on the web) inside Excel itself (rather than in Internet
Explorer) on the user's PC. Is it possible to have an ASP page that
does the same ? Thanks.
 
B

Bob Barrows

tianung said:
Thanks very much Bob. You've pointed out a fundamental concept. Just
so I don't bark up the wrong tree - would the following VB script that
opens an Excel spreadsheet on the user's PC be easily translatable to
an ASP page on the web ? Or would it similarly attempt to open on the
server side ?

Yes. See:
http://support.microsoft.com/default.aspx?scid=kb;en-us;257757
which warns about the dangers of server-side automation of Office
applications and provides links to alternatives.
 
F

Family Tree Mike

Bob said:
Yes. See:
http://support.microsoft.com/default.aspx?scid=kb;en-us;257757
which warns about the dangers of server-side automation of Office
applications and provides links to alternatives.

Though I completely agree with this when generating an Excel or other
office file, I think the question was regarding a pre-generated Excel
file. This could be answered with Response.ContentType and
Response.WriteFile. Now that I think about it, I'm not sure if
Resonse.WriteFile takes a url or only a local file though.
 
B

Bob Barrows

Family said:
Though I completely agree with this when generating an Excel or other
office file, I think the question was regarding a pre-generated Excel
file. This could be answered with Response.ContentType and
Response.WriteFile.

....which is the method illustrated in one of the links from this article.
 
T

tianung

Though I completely agree with this when generating an Excel or other
office file, I think the question was regarding a pre-generated Excel
file.  This could be answered with Response.ContentType and
Response.WriteFile.  Now that I think about it, I'm not sure if
Resonse.WriteFile takes a url or only a local file though.

As I know the above vbscript in its native form works nicely, is it
possible to use a ASP Classic script to do the following?

1. Either (A) copy the .vbs file from the web to the client's C:\
drive; or (B) create in the client's C:\ drive a text file with the
above vbscript code and then rename the text file (using ASP Classic)
so it has a .vbs extension;

2. Execute the newly created .vbs script in the client's C:\ drive
(using ASP Classic); and

3. Delete the .vbs script from the client's C:\ drive.

If this is possible at all, would it throw up a million alarm bells at
the user who activates the .asp script ?
 
B

Bob Barrows

tianung said:
As I know the above vbscript in its native form works nicely, is it
possible to use a ASP Classic script to do the following?

1. Either (A) copy the .vbs file from the web to the client's C:\
drive; or

No - too many hackers have taken advantage of that security hole to allow it
to be kept open ....
(B) create in the client's C:\ drive a text file with the
above vbscript code and then rename the text file (using ASP Classic)
so it has a .vbs extension;

Even worse ... !
2. Execute the newly created .vbs script in the client's C:\ drive
(using ASP Classic); and

No. ASP runs on the server (this applies to both ASP and ASP.Net) ..
3. Delete the .vbs script from the client's C:\ drive.
Egads!


If this is possible at all, would it throw up a million alarm bells at
the user who activates the .asp script ?

I would hope so!

I'm not sure why you are ignoring the alternative offered in the MS KB
article I pointed you at.
 
T

tianung

I'm not sure why you are ignoring the alternative offered in the MS KB
article I pointed you at.

Appreciate your trying to help but I saw only one relevant link within
one of the articles you quoted. It was the one that talked about
embedding the vbscript in an html document. Another 2 links also on
Excel did not apply to me as they talked about Office 2007 which I
don't have.

With the one that did relate to me, it threw up at least a couple of
ActiveX warnings at the user (I tried it on my PC). Also when placed
on the web, the script was completely ignored by my browser (won't
execute at all).

Which part of your articles in particular relates to opening an
existing Excel file stored on the web ? Can you please be more
specific ? Thanks.
 
B

Bob Barrows

tianung said:
Appreciate your trying to help but I saw only one relevant link within
one of the articles you quoted. It was the one that talked about
embedding the vbscript in an html document. Another 2 links also on
Excel did not apply to me as they talked about Office 2007 which I
don't have.

With the one that did relate to me, it threw up at least a couple of
ActiveX warnings at the user (I tried it on my PC). Also when placed
on the web, the script was completely ignored by my browser (won't
execute at all).

Which part of your articles in particular relates to opening an
existing Excel file stored on the web ? Can you please be more
specific ? Thanks.

I intended you to look at this one:

199841 How to display ASP results using Excel in IE with MIME types
.... which links to
http://support.microsoft.com/kb/199841/

But sorry, I was not thinking. You can simply redirect to the excel file
after setting the content type, like this:

<%
'set the MIME type to Excel
Response.ContentType = "application/vnd.ms-excel"
'then redirect to the excel file
response.Redirect "new x-ref.xls"
%>

The user will get prompted to open or save the file.

The major drawback to this approach is that it is not dynamic. You cannot
use a variable as the argument for the Redirect method.

If you won't know the name of the file until runtime, you will need to
stream the file as shown in this article:
http://support.microsoft.com/kb/276488
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top