'// 2.01.27.05
'// PermFix for standalone
'// To adjust permissions on folders for standalone web server
Option Explicit
On Error Resume Next

Dim oWebService, oPotentialSite, oCpmgr, oApp

Dim gszWebRoot, gszAutoaddfilesPath, gszUploadPath
Dim gszSSLPath, gszOptionsPath, gszLogFile
Dim count, pathArray, pathpos

gszLogFile = "c:\logfile.txt"

set oWebService = GetObject("IIS://LocalHost/W3SVC")
if (Err <> 0) then
	Log("Could not find W3SVC. Error: " & Err.Number)
	Wscript.Quit
end if

'// The list of web sites must be searched to find the match
set Err = 0
set count = 1
for each oPotentialSite in oWebService
	if oPotentialSite.Class = "IIsWebServer" then
		set oCpmgr = GetObject("IIS://LocalHost/W3SVC/"&count&"/root/cpmgr")
		if IsObject(oCpmgr) then
			pathArray = Split(oCpmgr.path,":")
			Exit for
		end if
	end if
	count = count + 1
next

gszWebRoot = pathArray(0) & ":\InetPub"
gszAutoaddfilesPath = pathArray(0) & ":\InetPub\wwwroot\cpmgr\AutoAddFiles"
gszUploadPath = pathArray(0) & ":\InetPub\wwwroot\cpmgr\Upload"
gszSSLPath = pathArray(0) & ":\InetPub\wwwroot\cpmgr\Ssl"
gszOptionsPath = pathArray(0) & ":\InetPub\wwwroot\cpmgr\Preferences\Options"

Set oApp = WScript.CreateObject("WScript.shell")

pathpos = InStrRev(WScript.ScriptFullName,"\")
If pathpos = 0 Then
	pathpos = InStr(WScript.ScriptFullName,":")
End If
oApp.run "cmd /c """& Left(WScript.ScriptFullName,pathpos) &"permfix_standalone.bat"" "&oWebService.AnonymousUserName&" "&gszWebRoot&" "&gszAutoaddfilesPath&" "&gszUploadPath&" "&gszSSLPath&" "&gszOptionsPath

'// Log()
'//
'// Write message to logfile.txt
'//
Sub Log(szText)
	On Error Resume Next
	Dim	oFS, oMsgFile, szFileName
	
	Debug.Write szText

	szFileName = gszLogFile

	set oFS = CreateObject("Scripting.FileSystemObject")
	set oMsgFile = oFS.OpenTextFile(szFileName,8,True)

	oMsgFile.WriteLine(szText)
	oMsgFile.Close
End Sub