Skip to content
This repository was archived by the owner on Feb 12, 2025. It is now read-only.

Commit 69d3282

Browse files
committed
Dashboard on IIS 7.5 installation fails (Bug #109) Installation on IIS7 (Support #43) rewrite install script for iis
1 parent 060cc17 commit 69d3282

File tree

1 file changed

+89
-138
lines changed

1 file changed

+89
-138
lines changed

install/createCCNetVDir.vbs

Lines changed: 89 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,27 @@ Option Explicit
1313
'Constants we use:
1414
' Starting with CCNet 1.3, we are a .NET 2.0 application:
1515
Dim DotNetFrameworkVersion: DotNetFrameworkVersion = "v2.0"
16+
1617
' We're going to create a "ccnet" virtual directory:
1718
Dim vdirName: vdirName = "ccnet"
18-
' We're going to create the virtual directory on web site #1:
19-
Dim webSiteNumber: webSiteNumber = "1"
19+
20+
' We're going to create the virtual directory on web site : Default Web Site
21+
Dim webSiteName: webSiteName = "Default Web Site"
22+
23+
'dedicated application pool for CruiseControl.Net
24+
Dim AppPoolName: AppPoolName="CruiseControl.Net"
25+
2026

2127
' Are we debugging this script?
2228
Dim DEBUG: DEBUG = false
2329

2430
createVDir()
2531

26-
' Create a virtual directory named vdirName on web site webSiteNumber using .NET version DotNetFrameworkVersion
32+
'good site with documentation about appcmd
33+
'http://blogs.msdn.com/b/mikezh/archive/2012/04/23/iis-appcmd-quick-reference.aspx
34+
35+
36+
' Create a virtual directory named vdirName on web site webSiteName using .NET version DotNetFrameworkVersion
2737
Function CreateVDir()
2838

2939
If WScript.Arguments.Count < 1 Then
@@ -32,161 +42,102 @@ Function CreateVDir()
3242
End If
3343

3444
Dim webdashboardInstallDir: webdashboardInstallDir = WScript.Arguments(0)
35-
36-
WScript.Echo "Searching for location of .NET framework version " & DotNetFrameworkVersion
37-
Dim DotNetFrameworkLocation
38-
DotNetFrameworkLocation = GetDotNetLocation(DotNetFrameworkVersion)
39-
If DotNetFrameworkLocation = "" Then
40-
WScript.Echo "Unable to location .NET framework version " & DotNetFrameworkVersion & "; cannot continue."
41-
WScript.Quit 6
42-
End If
43-
44-
45-
WScript.Echo "Checking whether there is an existing virtual directory with the name " & vdirName
46-
If DoesCCNetVDirExist(vdirName, webSiteNumber) Then
47-
WScript.Echo vdirName & " virtual directory already exists; cannot continue."
48-
WScript.Quit 3
45+
46+
WScript.Echo "Checking whether there is an existing virtual directory with the name " & vdirName
47+
If not DoesCCNetVDirExist(vdirName) Then
48+
CreateCCNetVDir webdashboardInstallDir, webSiteName, vdirName
4949
End If
50-
51-
Dim ccnetVDir: Set ccnetVDir = CreateCCNetVDir(webdashboardInstallDir, webSiteNumber)
52-
UpdateCCNetVDirScriptMaps ccnetVDir, webSiteNumber
53-
54-
If SetASPNETVersion(vdirName, webSiteNumber, DotNetFrameworkLocation) = False then
55-
WScript.Quit 5
56-
End if
5750

58-
' Confirm the creation
59-
WScript.Echo "Confirming that the virtual directory " & vdirName & " was created..."
60-
If DoesCCNetVDirExist(vdirName, webSiteNumber) = False Then
61-
WScript.Echo vdirName & " virtual directory creation failed."
62-
WScript.Quit 4
63-
End If
51+
SetASPNETVersion AppPoolName, DotNetFrameworkVersion, webSiteName, vdirName
52+
53+
' Confirm the creation
54+
WScript.Echo "Confirming that the virtual directory " & vdirName & " was created..."
55+
If not DoesCCNetVDirExist(vdirName) Then
56+
WScript.Echo vdirName & " virtual directory creation failed."
57+
WScript.Quit 4
58+
End If
6459

65-
WScript.Echo "Virtual directory for CruiseControl.NET Web Dashboard created successfully."
60+
WScript.Echo "Virtual directory for CruiseControl.NET Web Dashboard created successfully."
6661

6762
End Function
6863

69-
' Locate the installed copy of the specified .NET version
70-
' MajorVersion should be "vx.y" (e.g., "v2.0" for .NET 2.0)
71-
' Returns the full path to the framework (e.g., "C:\Windows\Microsoft.NET\Framework\v2.0.0.50727" for .NET 2.0).
72-
'
73-
' Based on an NSIS-script version from the NSIS wiki article "Get directory of installed .NET runtime"
74-
' (http://nsis.sourceforge.net/Get_directory_of_installed_.NET_runtime), converted to VBScript.
75-
Function GetDotNetLocation(majorVersion)
76-
' Assume failure:
77-
GetDotNetLocation = ""
78-
79-
Dim keyName
80-
' Because we can't just type "HKLM":
81-
Const wmi_HKLM = &H80000002
82-
83-
' Find the .NET framework via the registry:
84-
On Error Resume Next
85-
Dim objReg: Set objReg = GetObject("winmgmts:\\.\root\default:StdRegProv")
86-
If Err.Number <> 0 Then
87-
WScript.Echo "Error " & Err.Number & " opening the registry: " & Err.Description
88-
Exit Function
89-
End If
90-
keyName = "SOFTWARE\Microsoft\.NETFramework\policy\" & MajorVersion
91-
Dim subKeyList(), subkeyValues() : objReg.EnumValues wmi_HKLM, keyName, subKeyList, subKeyValues
92-
If DEBUG Then : WScript.Echo "[DEBUG] GetDotNetLocation(): found " & UBound(subKeyList)+1 & " keys under " & keyName : End If
93-
If Err.Number <> 0 Then
94-
WScript.Echo "Error " & Err.Number & " finding installed keys under HKLM\" & keyName & ": " & Err.Description
95-
Exit Function
96-
End If
97-
98-
Dim minorVersion : minorVersion = subKeyList(0)
99-
If DEBUG Then : WScript.Echo "[DEBUG] GetDotNetLocation(): minorVersion=" & minorVersion : End If
100-
keyName = "SOFTWARE\Microsoft\.NETFramework"
101-
Dim installRoot: objReg.GetStringValue wmi_HKLM, keyName, "InstallRoot", installRoot
102-
If DEBUG Then : WScript.Echo "[DEBUG] GetDotNetLocation(): installRoot=" & installRoot : End If
103-
If Err.Number <> 0 Then
104-
WScript.Echo "Error " & Err.Number & " getting InstallRoot key: " & Err.Description
105-
Exit Function
106-
End If
107-
GetDotNetLocation = installRoot & majorVersion & "." & minorVersion
108-
If DEBUG Then : WScript.Echo "[DEBUG] GetDotNetLocation(): GetDotNetLocation=" & GetDotNetLocation : End If
109-
110-
End Function
111-
11264
' Check if the specified virtual directory exists on the specified web site
11365
' Returns true if so, false if not.
114-
Function DoesCCNetVDirExist(vdirName, webSiteNumber)
115-
116-
Dim iisRoot
117-
Set iisRoot = GetObject("IIS://localhost/W3SVC/" & webSiteNumber & "/ROOT")
118-
Dim vdir
119-
For Each vdir in iisRoot
120-
If DEBUG Then : WScript.Echo "[DEBUG] DoesCCNetVDirExist(): found " & vdir.Name : End If
121-
If vdir.Name = vdirName Then
122-
DoesCCNetVDirExist = True
123-
Exit Function
124-
End If
125-
Next
66+
Function DoesCCNetVDirExist(vdirName)
12667
DoesCCNetVDirExist = False
12768

128-
End Function
69+
dim iisDirs
70+
iisDirs = getCommandOutput("cmd /c %systemroot%\system32\inetsrv\APPCMD list vdir")
71+
iisDirs = lcase(iisDirs)
12972

130-
Function CreateCCNetVDir(webdashboardInstallDir, webSiteNumber)
131-
132-
WScript.Echo "Creating virtual directory for CruiseControl.NET Web Dashboard at " & webdashboardInstallDir
133-
Dim iisRoot
134-
Set iisRoot = GetObject("IIS://localhost/W3SVC/" & webSiteNumber & "/ROOT")
135-
Dim ccnetVDir: set ccnetVDir = iisRoot.Create("IisWebVirtualDir", vdirName)
73+
If DEBUG Then : WScript.Echo "[DEBUG] IIs dirs found : " & vbcrlf & iisDirs : End If
74+
75+
if instr(iisDirs,vdirName) > 0 then 'vbs is NOT zero based !
76+
DoesCCNetVDirExist = true
77+
end if
78+
79+
End Function
13680

137-
ccnetVDir.AppCreate2 1
138-
ccnetVDir.AccessRead = True
139-
ccnetVDir.AccessScript = True
140-
' ccnetVDir.AccessNoRemoteExecute = True
141-
ccnetVDir.AppFriendlyName = "ccnet"
142-
ccnetVDir.KeyType = "IisWebVirtualDir"
143-
ccnetVDir.DefaultDoc = "default.aspx"
144-
ccnetVDir.DirBrowseFlags = &H40000000
145-
ccnetVDir.Path = webdashboardInstallDir
81+
Sub CreateCCNetVDir(webdashboardInstallDir, webSiteName, vdirName)
82+
83+
dim result
84+
dim command
85+
WScript.Echo "Creating virtual directory for CruiseControl.NET Web Dashboard at " & webdashboardInstallDir
86+
87+
command = "%systemroot%\system32\inetsrv\APPCMD add app /site.name:" & chr(34) & webSiteName & chr(34) & " /path:/" & vdirName & " /physicalpath:" & chr(34) & webdashboardInstallDir & chr(34)
88+
89+
result = getCommandOutput("cmd /c " & command)
90+
91+
If DEBUG Then : WScript.Echo "[DEBUG] IIs app creation : " & vbcrlf & result : End If
14692

147-
ccnetVDir.SetInfo()
148-
Set CreateCCNetVDir = ccnetVDir
93+
End Sub
14994

150-
End Function
15195

152-
Function UpdateCCNetVDirScriptMaps(ccnetVDir, webSiteNumber)
96+
Sub SetASPNETVersion(AppPoolName, DotNetFrameworkVersion, webSiteName, vdirName)
15397

154-
WScript.Echo "Updating the script maps for CruiseControl.NET virtual directory"
155-
Dim scriptMapCount
156-
Dim scriptMap
157-
Dim xmlScriptMap
98+
dim appPools
99+
dim result
100+
dim command
158101

159-
For Each scriptMap In ccnetVDir.ScriptMaps
160-
scriptMapCount = scriptMapCount + 1
161-
' Create a ".xml" script map based on the ".aspx" map:
162-
If InStr( scriptMap, ".aspx" ) Then
163-
xmlScriptMap = Replace( scriptMap, ".aspx", ".xml" )
164-
End If
165-
Next
102+
WScript.Echo "Setting application pool for CruiseControl.NET Web Dashboard " & AppPoolName & " to frameworkversion : " & DotNetFrameworkVersion
166103

167-
Dim iisRoot: Set iisRoot = GetObject("IIS://localhost/W3SVC/" & webSiteNumber & "/ROOT" )
168-
Dim scriptMaps: ScriptMaps = iisRoot.Get("ScriptMaps")
169-
ReDim Preserve scriptMaps(scriptMapCount)
170-
scriptMaps(scriptMapCount) = xmlScriptMap
104+
appPools = getCommandOutput("cmd /c %systemroot%\system32\inetsrv\APPCMD list apppool")
105+
appPools = lcase(appPools)
171106

172-
ccnetVDir.PutEx 2, "ScriptMaps", scriptMaps
173-
ccnetVDir.SetInfo
107+
If DEBUG Then : WScript.Echo "[DEBUG] IIs app pools found : " & vbcrlf & appPools : End If
108+
109+
if instr(appPools,lcase(AppPoolName)) = 0 then 'vbs is NOT zero based !
110+
WScript.Echo " * Creating application pool for CruiseControl.NET Web Dashboard " & AppPoolName & " frameworkversion : " & DotNetFrameworkVersion
111+
112+
command = "%systemroot%\system32\inetsrv\APPCMD ADD apppool /name:" & chr(34) & AppPoolName & chr(34) & " /managedRuntimeVersion:" & DotNetFrameworkVersion
113+
result = getCommandOutput("cmd /c " & command)
114+
If DEBUG Then : WScript.Echo "[DEBUG] IIs app creation : " & vbcrlf & result : End If
115+
end if
116+
117+
118+
command = "%systemroot%\system32\inetsrv\APPCMD set apppool " & chr(34) & AppPoolName & chr(34) & " /managedRuntimeVersion:" & DotNetFrameworkVersion
119+
result = getCommandOutput("cmd /c " & command)
120+
If DEBUG Then : WScript.Echo "[DEBUG] update app pool framework version : " & vbcrlf & result : End If
121+
122+
123+
command = "%systemroot%\system32\inetsrv\APPCMD set app " & chr(34) & webSiteName & "/" & vdirName & chr(34) & " /applicationpool:" & AppPoolName
124+
result = getCommandOutput("cmd /c " & command)
125+
If DEBUG Then : WScript.Echo "[DEBUG] IIs app set apppool : " & vbcrlf & result : End If
126+
127+
128+
129+
End Sub
174130

175-
End Function
176131

177-
Function SetASPNETVersion(vdirName, webSiteNumber, DotNetFrameworkLocation)
178-
179-
WScript.Echo "Setting .NET framework to " & DotNetFrameworkLocation & " for CruiseControl.NET virtual directory"
180-
Dim cmd: cmd = """" & DotNetFrameworkLocation & "\aspnet_regiis.exe"" -s ""W3SVC/" & webSiteNumber & "/ROOT/" & vdirName & """"
181-
If DEBUG Then : WScript.Echo "[DEBUG] SetASPNETVersion(): cmd=" & cmd : End If
182-
Dim wsh: Set wsh = WScript.CreateObject("WScript.Shell")
183-
Dim response: response = wsh.Run(cmd , 1, true )
184-
If ( response <> 0 ) Then
185-
WScript.Echo cmd & " failed; rc=" & response
186-
SetASPNETVersion = false
187-
Exit function
188-
End If
189-
SetASPNETVersion = true
132+
'
133+
' Capture the results of a command line execution and
134+
' return them to the caller.
135+
'
136+
Function getCommandOutput(theCommand)
190137

191-
End Function
138+
Dim objShell, objCmdExec
139+
Set objShell = CreateObject("WScript.Shell")
140+
Set objCmdExec = objshell.exec(thecommand)
141+
getCommandOutput = objCmdExec.StdOut.ReadAll
192142

143+
end Function

0 commit comments

Comments
 (0)