When you think ASP, think...
Recent Articles xml
All Articles
ASP.NET Articles
Related Web Technologies
User Tips!
Coding Tips
spgif spgif

Sample Chapters
JavaScript Tutorials
MSDN Communities Hub
Official Docs
Stump the SQL Guru!
XML Info
Author an Article
spgif spgif
ASP ASP.NET ASP FAQs Feedback topnav-right
Print this page.
Published: Wednesday, July 21, 1999

Executing Applications on a Server Through an ASP Page

Example: Getting Latest Versions From VSS
By Neema Moraveji

Executing applications on a computer from a remote location is something that many developers wish they had the ability to do. Well, here is a solution! You could write an ASP page so that you can go anywhere in the world, go to your server and execute a program that resides on your server - the possibilities are virtually limitless (you'll encounter a limitation in this article) to what you can use this for. On an intranet, this becomes particularly useful because there are many different uses for this application and you don't have to worry about security as much. For this article (my first) I am going to explain how to do this through a detailed example. Here is the scenario:

- continued -

Say you have a computer that is responsible for building the latest setup program for your internal tool. The process for building the build is simple: get the latest versions of the files from your source code management tool, compress certain files, and build the setup. In this case, we are using Microsoft Visual Source Safe 6 (VSS) as our source manager. So you want to create an ASP page where anybody on the intranet can visit, build the setup, and download it so they know they are getting the latest possible version. For this article, I will show you just the first step (getting the latest versions) - the rest of the process you can figure out and it will be different for every case.

This is where Genusa comes to the rescue (yet again). There is a free component provided by Genusa at http://www.serverobjects.com/products.htm#Aspexec called ASPExec which lets you execute command applications through an ASP page. The idea here is to execute a DOS batch file (eek!) that will do everything you want it to do. Lucky for us, VSS has a great command-line interface that will let us do just about anything we want with it. For more information about that, see the VSS Help File, it has all the switches, flags, and do-hickeys. But all we want to do is get the latest versions of the files in a certain project. It is important to note that the VSS server is located on the same computer at the web server. Why, do you ask?

Note: This explanation is somewhat technical. I have looked into this issue for weeks and tried workarounds but in the end, nothing worked. Basically, here is the story: in our batch file, you can see that we set the "ssDir" directory to a directory on our computer, so ss.exe has only to go to another directory on the drive to retrieve the information about the VSS project. But, when trying to enter something like "\\buddy\vss\" as your "ssDir" variable, you will notice that VSS won't be able to go across the network to get the information about the VSS server. This is because the IUSR_COMPNAME username on the NT machine does not have access to use the network resources on the server. I have tried giving IUSR_COMPNAME certain access and all types of things but nothing seems to work. People across the network can check in files to your VSS server freely, don't worry. Please note that your batch file will work with a VSS server across the network as long as you are executing it from the desktop and not through IIS. This is because YOU have access to go across the network, but not the IUSR_COMPNAME user that goes through IIS.

So, what we'll do is go ahead and create the batch file that will get the latest versions of the files:

@echo off REM Let's set the path so we can just call ss.exe without the path REM Note that the path on the machine will not change, just this REM temporary path for the user who is going through IIS set Path = %path%;C:\Program Files\Microsoft Developer Studio\VSS\Win32\; REM Now we need to set some environment variables for VSS REM the ssuser is your VSS username (ex. "Admin") set ssUser=vss_user REM this is the directory on your computer that has the "VSS.ini" file set ssDir=C:\Program Files\Microsoft Developer Studio\vss REM Let's change to the directory where we want the files to land cd "C:\Program Files\Microsoft Visual Studio\My Projects\Installer\" REM Finally, call VSS and use the "GET" command to get the REM latest versions of the files in the "$/setupfiles" project. REM Don't forget the "-i-" flag to signify it should skip any input ss GET "$/setupfiles" -i-

That's it! Now go ahead and test the batch file by running it on your machine. If it gets the latest versions of the files, then all you need to do is make your ASP page execute the batch file through the page and you're in business. The steps to create your ASP page are as follows:

1. Install the ASPExec component (register the component ASPExec.dll).
2. Create the ASP page (let's say build.asp) and make sure the user will have execute access on that file/directory.
3. Create the object on the page using CreateObject()
4. Set your parameters for the object
5. Call the Execute method
6. (Optional) Make sure it worked by checking a timestamp of a file.
7. If you are lazy enough, you can do the timestamp check using Genusa's free "LastMod" component.

<%@ Language = VBScript %>
<% Option Explicit %> <html> <head> <title>Get Latest Versions</title> </head> <body> Getting latest versions...<p> <% Dim objExecutor Dim sResult 'Create the server-side object Set objExecutor = Server.CreateObject("ASPExec.Execute") 'Set the application name 'For NT systems, it's "cmd.exe" 'If you're running something else then I think you know 'what it is :) objExecutor.Application = "cmd.exe" 'Now set the parameters, very important! 'You want your DOS prompt to call your batch file 'For NT - it's "/c filename.exe" objExecutor.Parameters = "/c c:\latest.bat" objExecutor.ShowWindow = False 'Here we execute the app and get the output to this string sResult = objExecutor.ExecuteWinApp Response.Write "Result: " & sResult & "<p>" %>

Done getting latest version.

Latest version of setup.ini file is

<% Dim objFSO Dim fFile Set objFSO = CreateObject("Scripting.FileSystemObject") Set fFile = objFSO.GetFile("C:\Program Files\Microsoft Visual Studio\Installer\setup.ini") Response.Write FormatDateTime(fFile.DateLastModified & ".",vbLongDate) %> </body> </html>

That's it - now test, test, test! It "should" work alright and you can experiment with doing very interesting things.


  • The Code for this Article in ZIP Format!

  • ASP.NET [1.x] [2.0] | ASPFAQs.com | Advertise | Feedback | Author an Article