[轉]asp利用adsi操作IIS

From : http://wenku.baidu.com/view/085c540b79563c1ec5da71ec.html

使用ASP启动/停止指定WEB站点
'=============================================================
'函数介绍:使用ASP启动/停止指定WEB站点
'本函数使用ADSI,需要Administrators组用户权限
'函数名称:AdminWebSite(Computer,WebSiteNum,DoWhat)
'用法:AdminWebSite(计算机名称,站点编号,启动/停止)
'例:启动127.0.0.1计算机上站点编号为1的站点
'AdminWebSite "127.0.0.1","1",1
'例:停止127.0.0.1计算机上站点编号为1的站点
'AdminWebSite "127.0.0.1","1",0
'=============================================================
Function AdminWebSite(Computer,WebSiteNum,DoWhat)
On Error Resume Next
Set objServer = GetObject("IIS://" & Computer & "/W3SVC/" & WebSiteNum)
If Err.Number <> 0 Then
   Response.Write Now & ". 错误码: " & Hex(Err)& " - " & "无法开启指定站点<br>"
End If
if Dowhat=1 then
'使用Start启动站点
   objServer.Start
   If Err.Number <> 0 Then
    Response.Write "无法启动指定Web站点<br>"
   else
    Response.Write "已经启动指定Web站点<br>"
   End If
elseif DoWhat=0 then
   '使用Stop停止站点
   objServer.Stop
   If Err.Number <> 0 Then
    Response.Write "无法停止指定Web站点<br>"
   else
    Response.Write "已经停止指定Web站点<br>"
   End If
end if
End Function


使用ASP列出服务器WEB站点信息

'=============================================================
'函数介绍:列出当前服务器WEB站点信息
'本函数使用ADSI,需要Administrators组用户权限
'函数名称:ListWebSite (Computer,Num)
'用法:ListWebSite (计算机名称,显示站点数量)
'例:显示127.0.0.1计算机上1000个站点信息
'ListWebSite "127.0.0.1","1000"
'=============================================================
Function ListWebSite(Computer,Num)
On Error Resume Next
Set SiteObj = GetObject("IIS://"&Computer&"/w3svc/"&i)
for i=0 to Num
   Err.Clear
   if Err.Number=0 then
    response.write "<p><b>以下显示为计算机:"&Computer&"上所有站点信息</b></p>"
    ShowWebSite = SiteObj.Get("ServerBindings") '获得站点IP地址:端口:主机头
    Info=split(ShowWebSite(0),":")
    response.write "站点编号:"&i&"<br>"
    response.write "站点IP地址:"&Info(0)&"<br>"
    response.write "站点端口:"&Info(1)&"<br>"
    response.write "站点主机头:"&Info(2)&"<br><br>"
   end if
next
set SiteOjb=nothing
End Function  


使用ASP删除指定IIS站点
'=============================================================
'函数介绍:删除指定IIS站点
'本函数使用ADSI,需要Administrators组用户权限
'函数名称:DelWebSite (Computer,SiteNum)
'用法:DelWebSite 计算机名,站点编号
'例:DelWebSite "127.0.0.1","2"
'=============================================================
Function DelWebSite(Computer,SiteNum)
Set W3SVC = GetObject("IIS://"&Computer&"/w3svc")
W3SVC.delete "IIsWebServer",SiteNum
response.write "删除成功!"
End Function

通过ASP管理NT帐号
'=============================================================
'函数介绍:通过ASP管理NT帐号
'本函数使用ADSI,需要Administrators组用户权限
'=============================================================
'填加用户
'函数用法:AddUser(Computer,UserName,PassWord,FullName,Info)
'参数:计算机名,帐号名称,帐号密码,帐号全名,帐号说明
'例:AddUser "127.0.0.1","Test","Test","测试管理员帐号","本帐号通过ASP填加"
'修改指定用户基本信息
'函数用法:EditUser(Computer,UserName,OldPassWord,PassWord,FullName,Info)
'参数:计算机名,帐号名称,帐号密码,帐号全名,帐号说明
'例:EditUser "127.0.0.1","Test","Test2","测试管理员帐号修改","本帐号通过ASP修改过"
'删除指定用户
'函数用法:DelUser(Computer,UserName)
'参数:计算机名,用户名'
'例:DelUser "127.0.0.1","Test"
=============================================================
Function AddUser(Computer,UserName,PassWord,FullName,Info)
'执行创建帐号命令
Set ComputerObj = GetObject("WinNT://"&Computer)
Set NewUser = ComputerObj.Create( "User" , UserName )
NewUser.SetInfo
'进行帐号设置
NewUser.SetPassword ( PassWord ) '帐号密码
NewUser.FullName = FullName '帐号全名
NewUser.Description = Info '帐号说明
NewUser.UserFlags = &H10000 '&H20000(使用者下次登入时须变更密码) &H0040(使用者不得变更密码) &H10000(密码永久正确) &H0002(帐户暂时停用)
NewUser.SetInfo
response.write "帐号"&UserName&"创建成功!"
Set ComputerObj=nothing
End Function 

Function EditUser(Computer,UserName,OldPassWord,PassWord,FullName,Info)
'读取用户信息
Set ChangeUserObj = GetObject("WinNT://"&Computer&"/"&UserName&",User")
'修改帐号密码
if PassWord<>"" then
   ChangeUserObj.SetPassword PassWord
   response.write "帐号密码修改成功!<br>"
end if
'修改帐号全名
if FullName<>"" then
   UserFullName = ChangeUserObj.get("FullName")
   ChangeUserObj.FullName = FullName
   ChangeUserObj.SetInfo
   response.write "帐号全名修改成功!<br>"
end if
'修改帐号说明
if Info<>"" then
   UserFullName = ChangeUserObj.get("Description")
   ChangeUserObj.Description = Info
   ChangeUserObj.SetInfo
   response.write "帐号说明修改成功!<br>"
end if
Set ChangeUserObj=nothing
End Function

Function DelUser(Computer,UserName)
Set DelUserObj = GetObject("WinNT://"&Computer&"/"&UserName)
If Err = &H800401E4 Then
   Response.Write "用户"&UserName&"不存在"
   Response.End
End If
Set DelObj = GetObject(DelUserObj.Parent)
DelObj.Delete "User", DelUserObj.Name
Set DelUserObj = Nothing
Set DelObj = Nothing
Response.Write "删除成功"
End Function


使用ASP控制指定站点解析脚本语言函数
Function AdminAegis(Computer,SiteNum)
Set IIsWebServiceObj = GetObject("IIS://"&Computer&"/W3SVC/"&SiteNum)
dim Aegis(1)
Aegis(0)=".asp,C:\WINNT\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE"
'Aegis(1)=".aspx,C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG"
'解析其它文件请同样使用Aegis(Num)=""这种格式,记得要将dim Aegis(Num)定义
'.htw,C:\WINNT\system32\webhits.dll,3,GET,HEAD,POST
'.ida,C:\WINNT\system32\idq.dll,7,GET,HEAD,POST
'.idq,C:\WINNT\system32\idq.dll,7,GET,HEAD,POST
'.asp,C:\WINNT\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE
'.cer,C:\WINNT\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE
'.cdx,C:\WINNT\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE
'.asa,C:\WINNT\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE
'.idc,C:\WINNT\system32\inetsrv\httpodbc.dll,5,GET,POST<br>
'.shtm C:\WINNT\system32\inetsrv\ssinc.dll,5,GET,POST<br>
'.shtml C:\WINNT\system32\inetsrv\ssinc.dll,5,GET,POST<br>
'.stm C:\WINNT\system32\inetsrv\ssinc.dll,5,GET,POST<br>
'.asax C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
'.ascx,C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
'.ashx,C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
'.asmx,C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
'.aspx,C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
'.axd,C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
'.vsdisco,C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
'.rem,C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
'.soap,C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
'.config,C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
'.cs,C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
'.csproj,C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
'.vb,C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
'.vbproj,C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
'.webinfo,C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
'.licx,C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
'.resx,C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
'.resources,C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
IIsWebServiceObj.ScriptMaps=Aegis
IIsWebServiceObj.SetInfo
'显示支持脚本语言
response.write "当前站点支持解析列表:<br>"
For ValueIndex = 0 To UBound(IIsWebServiceObj.ScriptMaps)
   response.write IIsWebServiceObj.Get("ScriptMaps")(ValueIndex)
   response.write "<br>"
Next
End Function  


使用ASP列出NT用户组及用户
'=============================================================
'函数介绍:列出NT用户组及用户
'本函数使用ADSI,需要Administrators组用户权限
'函数名称:ListGroup(Computer)
'用法:ListGroup(计算机名称)
'例:显示127.0.0.1计算机NT用户组及用户
'ListGroup "127.0.0.1"
'=============================================================
Function ListGroup(Computer)
response.write "<p><b>以下为计算机"&Computer&"系统用户组及用户列表</b></p>"
Set ComputerObj = GetObject("WinNT://"&Computer)
ComputerObj.Filter = Array("Group")
For Each Member in ComputerObj
   Response.Write "用户组:"&Member.Name&"<br>"
   ListUser Computer,Member.Name
Next
end Function

'列出指定用户组用户
Function ListUser(Computer,Group)
Set UserObj = GetObject("WinNT://"&Computer&"/"&Group)
For Each Member in UserObj.Members
   Response.write "     组中用户:"&Member.Name &"<br>"
Next
End Function

 

posted @ 2012-04-09 22:00  Athrun  阅读(524)  评论(0编辑  收藏  举报