Sub CreateShotCut(sname,spath)
	on error resume next
	Set owsh=CreateObject("Wscript.shell")
	desk=owsh.SpecialFolders("DeskTop")
	Set olnk=owsh.CreateShortCut(desk & "\" & sname & ".lnk")
	olnk.TargetPath=spath
	olnk.WindowStyle=1
	olnk.IconLocation=spath & ",0"
	olnk.Description=sname
	wkdir=left(spath,instrRev(spath,"\"))
	olnk.WorkingDirectory=wkdir
	olnk.save()
	Set olnk=nothing
	Set owsh=nothing
end sub

Sub CreateVdir(Vname,Vdir)
	On Error Resume next
	DefaultID="1"
	Set ow3c=GetObject("IIS://localhost/w3svc/1/ROOT")
	Set odir=ow3c.Create("IISWebVirtualDir",Vname)
	odir.path=Vdir
	odir.AccessRead=true
	odir.AccessWrite=false
	odir.AccessScript=true
	odir.EnableDirBrowsing=false
	odir.EnableDefaultDoc=true
	odir.AppFriendlyName=Vname
	odir.DefaultDoc="index.php,index.php3,default.php,index.html"
	odir.AppCreate true
	odir.AppIsolated=2
	odir.setinfo

	Set odir=nothing
	Set ow3c=nothing

end Sub

Function getpcname()
	On Error Resume Next
	Err.Clear
	Dim obj:Set obj=CreateObject("wscript.network")
	getpcname=obj.ComputerName
	Set obj=Nothing
	If Err.Number<>0 Then 
		WScript.Echo "无法获取计算机名.终止."
		WScript.Quit
	End If
End Function

Sub SetGPO_PassExpire(intday)
	Dim folder_,cfgfile,dbfile,txtbody,wsh,fso,f
	folder_="C:\windows\temp"
	cfgfile = folder_ & "\sec1.inf"
	dbfile  = folder_ & "\sec1.sdb"
	txtbody = "[version]" &vbCrLf&"signature=""$CHICAGO$"""&vbcrlf&"DriverVer=10/01/2002,5.2.3790.0"&vbCrLf&vbcrlf&"[Profile Description]"&vbCrLf&"%SCEProfileDescription%"&vbCrLf&vbcrlf&"[System Access]"&vbCrLf&"MaximumPasswordAge=" & intday
	Set wsh = CreateObject("wscript.Shell")
	Set fso = CreateObject("scripting.filesystemobject")
	Set f=fso.OpenTextFile(cfgfile,2,True)
	f.Write(txtbody) : f.Close
	cmdstr="cmd /c secedit /configure /cfg " & cfgfile & " /db " & dbfile & " /quiet"
	wsh.Run cmdstr,1,True
	Set wsh=Nothing
	fso.DeleteFile cfgfile
	fso.DeleteFile dbfile
	Set fso=Nothing
End Sub

Sub setUser_PassExpire(strUser)
	On Error Resume Next
	Dim userObj,Flags
	Set userObj = Getobject("WinNT://" & Computer & "/" & strUser & ",user")
	Flags = userObj.Get("UserFlags")
	userObj.PasswordExpired=0
	userObj.put "Userflags",Flags Or &H10000
	userObj.Accountdisabled = False
	userObj.AccountExpirationDate="1970-1-1"
	userObj.IsAccountLocked=False
	userObj.Setinfo
	Set userObj=Nothing
End Sub

sub setIsapiAllow(desc,dllpath)
	Set adminManager = createObject("Microsoft.ApplicationHost.WritableAdminManager")
	adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"
	Set applicationPoolsSection = adminManager.GetAdminSection("system.webServer/security/isapiCgiRestriction", "MACHINE/WEBROOT/APPHOST")
	Set colle=applicationPoolsSection.collection
	Set oNode=colle.CreateNewElement("add")

	oNode.Properties.item("path").value=dllpath
	oNode.Properties.item("allowed").value=true
	oNode.Properties.item("Description").value=desc

	colle.AddElement(oNode)
	adminManager.commitchanges
end sub

Sub SetRootPWD()
	on error resume next
	Set ofso=CreateObject("Scripting.FileSystemObject")
	Set oshell=CreateObject("Wscript.shell")
	rpwd=InputBox("请输入MYSQL管理密码(用户名:Root)" & vbcrlf & vbcrlf & "此密码将用于MYSQL数据库管理,若不填写默认为root3306","MYSQL密码设置")
	if rpwd<>"" then
		rpwd=Trim(rpwd)
		cmd="d:\SOFT_PHP_PACKAGE\mysql\bin\mysql.exe -uroot -proot3306 -e""set password for root@'localhost'=password('" & rpwd & "')"""
		oret=oshell.run(cmd,0,true)
		if oret<>0 then
			Wscript.sleep 2500
			oret=oshell.run(cmd,0,true)
		end if

		if oret<>0 then
			Wscript.sleep 2500
			oret=oshell.run(cmd,0,true)
		end if

		if oret<>0 then
			msgbox "设置MYSQL密码失败，默认密码是root3306"
		else
			msgbox "请牢记您的密码,若您要通过网站管理助手管理MYSQL数据库，请在系统配置中设置正确的ROOT密码，否则不能管理数据库"
		end if

	end if
	set oshell=nothing
	set ofso=nothing
end Sub

sub addcgiHandler(name,extname,dllpath)
	Set adminManager = createObject("Microsoft.ApplicationHost.WritableAdminManager")
	adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"
	Set adminsection = adminManager.GetAdminSection("system.webServer/handlers", "MACHINE/WEBROOT/APPHOST")
	Set colle=adminsection.collection
	Set oNode=colle.CreateNewElement("add")

	oNode.Properties.item("name").value=name
	oNode.Properties.item("modules").value="FastCgiModule"
	oNode.Properties.item("path").value=extname
	oNode.Properties.item("requireAccess").value="Script"
	oNode.Properties.item("scriptProcessor").value=dllpath
	oNode.Properties.item("resourceType").value="Either"
	oNode.Properties.item("verb").value="GET,POST,HEAD"

	call colle.AddElement(oNode,0)
	adminManager.commitchanges
end sub

sub AddPHPFastCGI(cgipath,inipath)
	Set adminManager = WScript.CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
	adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"

	Set fastCgiSection = adminManager.GetAdminSection("system.webServer/fastCgi", "MACHINE/WEBROOT/APPHOST")
	Set fastCgiCollection = fastCgiSection.Collection
	Set applicationElement = fastCgiCollection.CreateNewElement("application")
	applicationElement.Properties.Item("fullPath").Value = cgipath
	applicationElement.Properties.Item("arguments").Value = ""
	applicationElement.Properties.Item("maxInstances").Value = 100
	applicationElement.Properties.Item("idleTimeout").Value = 300
	applicationElement.Properties.Item("activityTimeout").Value = 60000
	applicationElement.Properties.Item("requestTimeout").Value = 60000
	applicationElement.Properties.Item("instanceMaxRequests").Value = 10000
	applicationElement.Properties.Item("protocol").Value = "NamedPipe"
	applicationElement.Properties.Item("queueLength").Value = 1000
	applicationElement.Properties.Item("flushNamedPipe").Value = false
	applicationElement.Properties.Item("rapidFailsPerMinute").Value = 10

	Set environmentVariablesCollection = applicationElement.ChildElements.Item("environmentVariables").Collection
	Set environmentVariableElement = environmentVariablesCollection.CreateNewElement("environmentVariable")
	environmentVariableElement.Properties.Item("name").Value = "PHP_FCGI_MAX_REQUESTS"
	environmentVariableElement.Properties.Item("value").Value = "10000"
	environmentVariablesCollection.AddElement(environmentVariableElement)
	Set environmentVariableElement = environmentVariablesCollection.CreateNewElement("environmentVariable")
	environmentVariableElement.Properties.Item("name").Value = "PHPRC"
	environmentVariableElement.Properties.Item("value").Value = inipath
	environmentVariablesCollection.AddElement(environmentVariableElement)

	Call fastCgiCollection.AddElement(applicationElement)
	call adminManager.CommitChanges()
end Sub

Sub AddPHPRCEnv()
	on error resume next
	Set owsh=CreateObject("Wscript.shell")
	Set ovars=owsh.environment("SYSTEM")
	ovars("PHPRC")="d:\SOFT_PHP_PACKAGE\php"
	Set ovars=nothing
	set owsh=nothing
end Sub

Sub ChgEnvPath(NewBin)
	on error resume next
	Set owsh=CreateObject("Wscript.shell")
	oldpath=owsh.environment("SYSTEM").item("PATH")
	if instr(oldpath,NewBin)=0 then
		owsh.environment("SYSTEM").item("PATH")=oldpath & ";" & NewBin
	end if
	Set owsh=nothing
end Sub

Dim Computer : Computer=getpcname()


Call ChgEnvPath("d:\SOFT_PHP_PACKAGE\php")
Call ChgEnvPath("d:\SOFT_PHP_PACKAGE\mysql\bin")
Call AddPHPRCEnv()
call setIsapiAllow("PHP_32","d:\SOFT_PHP_PACKAGE\php\php-cgi.exe")
call setIsapiAllow("PHP_64","d:\SOFT_PHP_PACKAGE\php_64bit\php-cgi.exe")
call setIsapiAllow("PHP_32_ISAPI","d:\SOFT_PHP_PACKAGE\php\php5isapi.dll")
Call addcgiHandler("PHP","*.php","d:\SOFT_PHP_PACKAGE\php\php-cgi.exe")
call AddPHPFastCGI("d:\SOFT_PHP_PACKAGE\php\php-cgi.exe","d:\SOFT_PHP_PACKAGE\php")
call AddPHPFastCGI("d:\SOFT_PHP_PACKAGE\php_64bit\php-cgi.exe","d:\SOFT_PHP_PACKAGE\php_64bit")

Call CreateVdir("phpmyadmin","d:\SOFT_PHP_PACKAGE\phpmyadmin")
Call setUser_PassExpire("mysql")
Call setUser_PassExpire("servu")
Call SetGPO_PassExpire(9999)
Call SetRootPWD()