極光下載站 - 打造齊全的綠色軟件家園

極光下載站

當前位置: 首頁 技術開發 ASP專區 ASP控制虛擬主機函數ADSI

ASP控制虛擬主機函數ADSI

時間:2006/7/19 16:09:54 作者:佚名 人氣:335

使用ASP設置指定站點CPU最大使用程度
'=================================================
'函數介紹:設置指定站點CPU最大使用程度
'本函數使用ADSI,需要Administrators組用戶權限
'函數名稱:SetCPULimitVar (Computer,SiteNum,LimitVar)
'用法:SetCPULimitVar 計算機名,站點編號,最大限制值(100=1%,1000=10%)
'例:SetCPULimitVar "LocalHost","2","2000"
'=================================================
Function SetCPULimitVar(Computer,SiteNum,LimitVar)
Set MyObj001 = GetObject("IIS://"&Computer&"/W3SVC/"&SiteNum)
'設置啟用CPU限制
MyObj001.CpuLimitsEnabled = True
'設置限制使用額度值
MyObj001.CpuLimitLogEvent=LimitVar
MyObj001.setinfo
Set MyObj001=Nothing
End Function

使用ASP在IIS創建WEB站點的函數
'=============================================================
'函數介紹:創建WebSite
'本函數使用ADSI,需要Administrators組用戶權限
'函數名稱:CreateWebSite(Computer,IPAddr,PortNum,HostName,WebSiteDirectory,LogDirectory,WebSiteInfo,GuestUserName,GuestUserPass,StartOrStop)
'用法:CreateWebSite 計算機名(一搬為LocalHost或127.0.0.1),站點IP地址,端口號,主機名,站點根目錄,,LOG文件的目錄站點說明,網站訪問時所使用的帳號,網站訪問時所用帳號的口令,是否啟動站點
'例:CreateWebSite "LocalHost","127.0.0.123","80","www.test.net","E:\UserData\UserNum001","E:\UserData\UserNum001\LogFiles","wwwtest.net","IUSR_Num001_test.net","abc888",True
'=============================================================
Function CreateWebSite(Computer,IPAddr,PortNum,HostName,WebSiteDirectory,LogDirectory,WebSiteInfo,GuestUserName,GuestUserPass,StartOrStop)
Dim w3svc, WebServer, NewWebServer, NewDir
Dim Bindings, BindingString, NewBindings, SiteNum, SiteObj, bDone
On Error Resume Next
Err.Clear
'檢測是否能夠加載W3SVC服務(即WEB服務)
Set w3svc = GetObject("IIS://" & Computer & "/w3svc")
If Err.Number <> 0 Then '顯示錯誤提示
  response.write "無法打開: "&"IIS://" & Computer & "/w3svc"
  response.end
End If
'檢測是否有設定相同IP地址、端口及主機名的站點存在
BindingString = IPAddr & ":" & PortNum & ":" & HostName
For Each WebServer in w3svc
  If WebServer.Class = "IIsWebServer" Then
  Bindings = WebServer.ServerBindings
   If BindingString = Bindings(0) Then
    response.write "IP地址沖突:" & IPAddr & ",請檢測IP地址!."
    Exit Function
   End If
  End If
Next


'確定一個不存在的站點編號做為新建站點編號,系統默認WebSite站點編號為1,因此從2開始
SiteNum=2
bDone = False
While (Not bDone)
Err.Clear
Set SiteObj = GetObject("IIS://"&Computer&"/w3svc/"&SiteNum) '加載指定站點
If (Err.Number = 0) Then
  'response.write " Step_1站點"&SiteNum&"存在"
  SiteNum = SiteNum + 1
Else
  'response.write " Step_1站點"&SiteNum&"不存在"
  Err.Clear
  Set NewWebServer = w3svc.Create("IIsWebServer",SiteNum) '創建指定站點
  If (Err.Number <> 0) Then
   'response.write " Step_2站點"&SiteNum&"創建失敗"
   SiteNum = SiteNum + 1
  Else
   'response.write " Step_2站點"&SiteNum&"創建成功"
   bDone = True
  End If
End If
If (SiteNum > 50) Then '服務器最大創建站點數
  response.write "超出服務器最大創建站點數,正在創建的站點的序號為: "&SiteNum&"."
  response.end
End If
Wend


'進行站點基本配置
NewBindings = Array(0)
NewBindings(0) = BindingString
NewWebServer.ServerBindings = NewBindings
NewWebServer.ServerComment= WebSiteInfo
NewWebServer.AnonymousUserName= GuestUserName
NewWebServer.AnonymousUserPass= GuestUserPass
NewWebServer.KeyType = "IIsWebServer"
NewWebServer.FrontPageWeb = True
NewWebServer.EnableDefaultDoc = True
NewWebServer.DefaultDoc = "Default.htm, Default.asp, Index.htm, Index.asp"
NewWebServer.LogFileDirectory= LogDirectory
NewWebServer.SetInfo
Set NewDir = NewWebServer.Create("IIsWebVirtualDir", "ROOT")
NewDir.Path = WebSiteDirectory
NewDir.AccessRead = true
NewDir.AppFriendlyName = "應用程序" & WebSiteInfo
NewDir.AppCreate True
NewDir.AccessScript = True
Err.Clear
NewDir.SetInfo
If (Err.Number <> 0) Then
  response.write "主目錄創建時出錯."
  response.end
End If
If StartOrStop = True Then
  Err.Clear
  Set NewWebServer = GetObject("IIS://" & Computer & "/w3svc/" & SiteNum)
  NewWebServer.Start
  If Err.Number <> 0 Then
   response.write "啟動站點時出錯!"
   response.end
   Err.Clear
  End If
End If
response.write "站點創建成功,站點編號為:"& SiteNum &" ,域名為:"& HostName
End Function


使用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 "&nbsp;&nbsp;&nbsp;&nbsp;組中用戶:"&Member.Name &"<br>"
Next
End Function


<
標簽
分享到:

公眾號

彩票平台大全