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 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 AddExt(PHPDIR)
	on error resume next
	Set ow3=GetObject("IIS://localhost/w3svc")
	xlist=ow3.WebSvcExtRestrictionList
	x="1," & PHPDIR & ",1,PHP,SOFT PHP PACKAGE"
	blAdd=true
	for each xitem in xlist
		if instr(xitem,x)>0 then
			blAdd=false
			Exit Sub
		end if
	next
	if blAdd then
		redim preserve xlist(Ubound(xlist)+1)
		xlist(Ubound(xlist))=x
		ow3.WebSvcExtRestrictionList=xlist
		ow3.setInfo
	end if
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

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

	Call AddScriptMaps("1")
end Sub

Sub AddScriptMaps(SID)
	on error resume next
	phplist=split(".php,d:\SOFT_PHP_PACKAGE\php\php-cgi.exe,5,GET,HEAD,POST,TRACE;.php3,d:\SOFT_PHP_PACKAGE\php\php-cgi.exe,5,GET,HEAD,POST,TRACE",";")
	if isNumeric(SID) then
		Set ow3svc=GetObject("IIS://localhost/w3svc/" & SID & "/ROOT")
	else
		Set ow3svc=GetObject("IIS://localhost/w3svc")
	end if
	oscripts=ow3svc.ScriptMaps
	for each maps in phplist
		redim preserve oscripts(Ubound(oscripts)+1)
		oscripts(ubound(oscripts))=maps
	next
	ow3svc.ScriptMaps=oscripts
	ow3svc.SetInfo
	Set ow3svc=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 SetRootPWD()
	on error resume next
	Set ofso=CreateObject("Scripting.FileSystemObject")
	Set oshell=CreateObject("Wscript.shell")
	setf="soft\setup.ini"
	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
			if ofso.fileExists(setf) then
				Set ofs=ofso.opentextfile(setf,1,false)
				tcon=ofs.readall
				ofs.close:set ofs=nothing
				Set ofs=ofso.openTextFile(setf,2,false)
				Call ofs.write(replace(tcon,"MYROOT=root3306","MYROOT=" & rpwd))
				ofs.close:set ofs=nothing
			end if
		end if

	end if
	set oshell=nothing
	set ofso=nothing
end Sub
Dim Computer : Computer=getpcname()

Call ChgEnvPath("d:\SOFT_PHP_PACKAGE\php")
Call ChgEnvPath("d:\SOFT_PHP_PACKAGE\mysql\bin")
Call AddExt("d:\SOFT_PHP_PACKAGE\php\php-cgi.exe")
Call AddExt("d:\SOFT_PHP_PACKAGE\php\php5isapi.dll")
Call AddPHPRCEnv()
Call AddScriptMaps("NONE")
Call CreateVdir("phpmyadmin","d:\SOFT_PHP_PACKAGE\phpmyadmin")
Call setUser_PassExpire("mysql")
Call setUser_PassExpire("servu")
Call SetGPO_PassExpire(9999)
Call SetRootPWD()