Harish
Posts: 35
Joined: Tue Dec 27, 2005 9:25 am

Stopping IIS and restarting

Hi,

I have one more problem. I have a dll related to IIS. I mean if IIS is running it will not be registered. So IIS should be stopped first and every thing has to installed including dll registration and at last IIS should be started. In simple terms IIS should be stopped uninstall the previous version, install the latest and then IIS should be started.

How can it be done. Should we write an vbs.

Thanks in Advance,
Harish.Y
ciprian
Posts: 259
Joined: Thu Jul 14, 2005 12:56 pm
Location: Craiova, Romania
Contact: Website

Hi Harish,

This could be achieved with the use of two custom actions.

The first custom action is to be executed at the beginning of the install process and it will stop the IIS. For example, you can schedule it under the "InstallInitialize" standard action.

Here is a VBScript that stops the IIS server:

Code: Select all

Const SITE_STOPPED = 4
Set objIIsWebService = GetObject("IIS://localhost/W3SVC")
For Each Site in objIIsWebService
  If Site.Class = "IIsWebServer" Then
    Set objIIsWebServer = GetObject(Site.ADsPath)
    intStatus = objIIsWebServer.Status
    If intStatus <> SITE_STOPPED Then
      objIIsWebServer.Stop
      WScript.Sleep 3000
      intStatus = objIIsWebServer.Status
      If intStatus = SITE_STOPPED Then
        WScript.Echo "Web server stopped."
      Else
        WScript.Echo "The Web server did not stop."
      End If
    Else
      WScript.Echo "The Web server is already stopped."
    End If
  End If
Next
The second custom action is to be execute at the end of the installation say, under the "InstallFinalize" standard action. This custom action will restart the IIS.

Here is a VBScrip that does that:

Code: Select all

Const SITE_STARTED = 2
Set objIIsWebService = GetObject("IIS://localhost/W3SVC")
For Each Site in objIIsWebService
  If Site.Class = "IIsWebServer" Then
    Set objIIsWebServer = GetObject(Site.ADsPath)
    intStatus = objIIsWebServer.Status
    If intStatus <> SITE_STARTED Then
      objIIsWebServer.Start
      WScript.Sleep 3000
      intStatus = objIIsWebServer.Status
      If intStatus = SITE_STARTED Then
        WScript.Echo "Web server started."
      Else
        WScript.Echo "The Web server did not start."
      End If
    Else
      WScript.Echo "The Web server is already started."
    End If
  End If
Next
Best regards,
Ciprian
Ciprian Burca
Advanced Installer Team
http://www.advancedinstaller.com

Return to “Common Problems”