Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / web / ASP.NET

ASP Application installer using Javascript

1.57/5 (7 votes)
4 Aug 2010CPOL 1   112  
How to install an ASP.NET application using Javascript. This will register your application in IIS, create a start menu entry and desktop icon.

Introduction

This is an application for those who want to install .NET web applications but do not want to create a setup application. The code presented in this article can be used to create an easy installer.

Background

This application is developed using Javascript.

Using the code

You can use the following install and uninstall Javascript in your application and also the Javascript file available in common folder

The Javascript for for installing an application is as follows:

HTML
<script language="JScript">
////////////////////////////////////////////////////////////////
function window.onload()
////////////////////////////////////////////////////////////////
{
    if (document.location.protocol != "file:")
    {
        alert("This application must be run under the file protocol")
        window.close()
        return
    }
    document.all.virtualDir.value = "TestInstall"
    document.all.virtualDir.readOnly = true
    initTabbedContent()
    populateWebsiteList()
    document.title = Product + " Installation"
    sizeWindow()
}

////////////////////////////////////////////////////////////////
function installSuite()
////////////////////////////////////////////////////////////////
{
    var cwd = WshShell.CurrentDirectory;

    for ( var i = 0; i < ProductArray.length -1; i++ )
    {
        Product = ProductArray[i];
        PublicFolders = PublicFoldersArray[i];
        WshShell.CurrentDirectory = "./" + Product + "/";
//        WshShell.Run( "install.hta auto", 2, true )

        install(true); 
        WshShell.CurrentDirectory = cwd;
    }     
    Product = ProductArray[ ProductArray.length-1 ];
    PublicFolders = PublicFoldersArray[ ProductArray.length-1 ];
    document.getElementById("virtualDir").value = Product;
    document.getElementById("virtualDir").originalValue = Product;
    install();
    updateText( "Test installation complete.");
}
</script>

The script to uninstall an application is as follows:

ASP.NET
<script language="JScript" src="common/uninstall.js"></script>
<script language="JScript">
var SubProductArray = 
[
    //Define your sub folders here
];
////////////////////////////////////////////////////////////////
function window.onload()
////////////////////////////////////////////////////////////////
{
    if (!loadInstallationProperties())
    {
        alert("Cannot load installation properties file install.xml");
        window.close();
    }
    webSite = getInstallationProperty("website");
    virtualDir = getInstallationProperty("virtualdir");
    product = getInstallationProperty("product");
    shortProduct = product.split(".")[0];
    dotNet = true;

    installshield = 
      (TestUnInstall.commandLine.toLowerCase().indexOf("installshield") >= 0);
    sizeWindow();
    if (installshield)
    {
        document.all.buttonRow.style.display = "none";
        uninstallSuite();
        window.close();
    }
}
////////////////////////////////////////////////////////////////
function uninstallSuite()
////////////////////////////////////////////////////////////////
{
    var preservedVirtualDir = virtualDir;

    updateText("Beginning uninstall");
    for (var i = 0; i < SubProductArray.length; i++)
    {
        virtualDir = SubProductArray[ i ];
        removeVirtualFolder();
    }
    virtualDir = preservedVirtualDir;
    uninstall();
}
</script>

Points of Interest

During development of this application I learned how Javascript can be powerful on the client side. I also learned how to change the web.config file at installation time.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)