.vbs to ASP page

Discussion in 'ASP General' started by tianung, Jul 19, 2009.

  1. tianung

    tianung Guest

    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 !
     
    tianung, Jul 19, 2009
    #1
    1. Advertising

  2. tianung

    Bob Barrows Guest

    tianung wrote:
    > 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.


    --
    Microsoft MVP - ASP/ASP.NET - 2004-2007
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"
     
    Bob Barrows, Jul 19, 2009
    #2
    1. Advertising

  3. tianung wrote:
    >
    > 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.

    --
    Mike
     
    Family Tree Mike, Jul 19, 2009
    #3
  4. tianung

    tianung Guest

    On Jul 19, 11:04 pm, "Bob Barrows" <> wrote:
    >
    > 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.
     
    tianung, Jul 19, 2009
    #4
  5. tianung

    Bob Barrows Guest

    tianung wrote:
    > On Jul 19, 11:04 pm, "Bob Barrows" <> wrote:
    >>
    >> 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 ?
    >


    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.

    --
    Microsoft MVP - ASP/ASP.NET - 2004-2007
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"
     
    Bob Barrows, Jul 19, 2009
    #5
  6. tianung

    Bob Barrows Guest

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


    Building on Mike's reply, these are relevant for you as well:
    http://www.boutell.com/newfaq/definitions/asp.html
    http://www.packtpub.com/article/Classic-ASP (some of the information in this
    is incorrect, or is no longer valid - however, the main points still hold
    water)
    http://www.takempis.com/aspnet_fundamentals.asp

    --
    Microsoft MVP - ASP/ASP.NET - 2004-2007
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"
     
    Bob Barrows, Jul 19, 2009
    #6
  7. Bob Barrows wrote:
    > tianung wrote:
    >> On Jul 19, 11:04 pm, "Bob Barrows" <> wrote:
    >>> 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 ?
    >>

    >
    > 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.

    --
    Mike
     
    Family Tree Mike, Jul 19, 2009
    #7
  8. tianung

    Bob Barrows Guest

    Family Tree Mike wrote:
    > Bob Barrows wrote:
    >> tianung wrote:
    >>> On Jul 19, 11:04 pm, "Bob Barrows" <> wrote:
    >>>> 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 ?
    >>>

    >>
    >> 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.


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

    --
    Microsoft MVP - ASP/ASP.NET - 2004-2007
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"
     
    Bob Barrows, Jul 19, 2009
    #8
  9. tianung

    tianung Guest

    On Jul 20, 3:27 am, Family Tree Mike <>
    wrote:
    >
    > 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 ?
     
    tianung, Jul 20, 2009
    #9
  10. tianung

    Bob Barrows Guest

    tianung wrote:
    > On Jul 20, 3:27 am, Family Tree Mike <>
    > wrote:
    >>
    >> 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


    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.

    --
    Microsoft MVP - ASP/ASP.NET - 2004-2007
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"
     
    Bob Barrows, Jul 20, 2009
    #10
  11. tianung

    tianung Guest

    On Jul 20, 12:22 pm, "Bob Barrows" <> wrote:

    > 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.
     
    tianung, Jul 20, 2009
    #11
  12. tianung

    Bob Barrows Guest

    tianung wrote:
    > On Jul 20, 12:22 pm, "Bob Barrows" <> wrote:
    >
    >> 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.


    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

    --
    Microsoft MVP - ASP/ASP.NET - 2004-2007
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"
     
    Bob Barrows, Jul 20, 2009
    #12
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brad

    Running a VBS file from ASP.NET

    Brad, Aug 28, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    530
  2. =?Utf-8?B?RGFuQw==?=

    Running Xcacls.vbs on ASP.net page fails

    =?Utf-8?B?RGFuQw==?=, Nov 15, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    731
    =?Utf-8?B?RGFuQw==?=
    Nov 15, 2005
  3. ben h

    .vbs function in an .asp page?

    ben h, Sep 13, 2004, in forum: ASP General
    Replies:
    1
    Views:
    190
    Dave Anderson
    Sep 13, 2004
  4. p byers

    Executing a VBS file from an ASP page

    p byers, Mar 11, 2008, in forum: ASP General
    Replies:
    4
    Views:
    298
    p byers
    Mar 12, 2008
  5. Zhiguo
    Replies:
    5
    Views:
    223
    Zhiguo
    Dec 10, 2009
Loading...

Share This Page