Делаешь 2 VBScript Custom actions WebSiteInstallExecute и WebSiteUninstallExecute:
Обе запускаешь в Deferred execution блоке с msidbCustomAction
TypeNoImpersonate флагом.
Ну и естественно присваиваешь WebSiteInstallExecute и WebSiteUninstallExecute property соотвествующие значения в Intermeduate блоке.
'// MSI Custom Action
'// IIS web site Installation //
'// Infopulse Ukraine //
'// Oleg Nalyvaiko //
'// oleg.nalyvaiko@infopulse.com.ua
'////////////////////////////////////////////////////
Const msiMessageTypeError = &H01000000 ' Formatted error message
Const msiMessageTypeInfo = &H04000000 ' Informative message for log, not to be displayed.
Const msiMessageTypeUser = &H03000000 ' User request message
Const msiERROR_INVALID_PARAMETER = 87
' custom error codes
Const msiERROR_IIS_SERVER_NOT_FOUND = 1800
Function Show_Message(msgType, msgText)
if msgType <= msiMaxMessageType then
Set record = Session.Installer.CreateRecord(0)
record.StringData(0) = msgText
Show_Message = Session.Message(msgType, record)
end if
End Function
' ----------------------------------
' Uninstall web site
' Set WebSiteUninstallExecute property to the [_IIS_SERVER_NAME]|[_IIS_WEB_NAME]
' for getting parameters through CustomActionData in the deferred execution
Function WebSiteUninstallExecute()
Dim ServerName, ApplicationName
Dim sParameters: sParameters = Split(Session.Property("CustomActionData"), "|")
if UBound(sParameters) <> 1 then
Show_Message msiMessageTypeInfo "Invalid parameters " & Session.Property("CustomActionData")
WebSiteUninstallExecute = msiERROR_INVALID_PARAMETER
end if
ServerName = sParameters(0) ' Session.Property("_IIS_SERVER_NAME")
ApplicationName = sParameters(1) ' Session.Property("_IIS_WEB_NAME")
Dim objIIS, objIISRoot
Set objIISRoot = GetObject("IIS://" + ServerName + "/W3SVC/1/Root")
If objIISRoot Is Nothing Then
Show_Message msiMessageTypeInfo "Cannot found IIS server at " & ServerName
WebSiteUninstallExecute = 1
Exit Function
End If
On Error Resume Next
Set objIIS = objIISRoot.GetObject("", ApplicationName)
If Err.Number = 0 Then
objIIS.AppUnload
objIIS.AppDelete
End If
Set objIIS = Nothing
Set objIISRoot = Nothing
WebSiteUninstallExecute = 1
End Function
' ----------------------------------
' Install web site
' Set WebSiteInstallExecute property to the [_IIS_SERVER_NAME]|[_IIS_WEB_NAME]|[INSTALLDIR]
' for getting parameters through CustomActionData in the deferred execution
Function WebSiteInstallExecute()
Dim sParameters: sParameters = Split(Session.Property("CustomActionData"), "|")
if UBound(sParameters) <> 2 then
Show_Message msiMessageTypeInfo "Invalid parameters " & Session.Property("CustomActionData")
WebSiteInstallExecute = msiERROR_INVALID_PARAMETER
end if
Dim ServerName, ApplicationName, LocalPath
ServerName = sParameters(0)
ApplicationName = sParameters(1)
LocalPath = sParameters(2)
Dim objIIS, objIISRoot
Set objIISRoot = GetObject("IIS://" + ServerName + "/W3SVC/1/Root")
If objIISRoot Is Nothing Then
Show_Message msiMessageTypeInfo "Cannot found IIS server at " & ServerName
WebSiteInstallExecute = msiERROR_IIS_SERVER_NOT_FOUND
End If
On Error Resume Next
Set objIIS = objIISRoot.GetObject("IIsWebDirectory", ApplicationName)
If Err.Number = -2147024893 Then
On Error Goto 0
If LocalPath = "N/A" Then
Set objIIS = objIISRoot.Create("IIsWebDirectory", ApplicationName)
Else
Set objIIS = objIISRoot.Create("IIsWebVirtualDir", ApplicationName)
objIIS.Path = LocalPath + "\" + ApplicationName
objIIS.SetInfo
Set objIIS = objIISRoot.GetObject("", ApplicationName)
End If
ElseIf Err.Number = -2147463160 Then
On Error Goto 0
Set objIIS = objIISRoot.GetObject("", ApplicationName)
End If
On Error Goto 0
objIIS.AuthAnonymous = False
objIIS.AuthNTLM = True
objIIS.DefaultDoc = "default.aspx"
objIIS.SetInfo
objIIS.AppCreate 0
Set objIIS = Nothing
Set objIISRoot = Nothing
WebSiteInstallExecute = 1
End Sub