|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
只要你想学,就没什么优缺点,上面那位大哥已经把网上的评论说了,但我认为想学哪个都一样,不然它就不可能在当今时代数字艺术方面存活到今天dns办事器|掌握 在VB中要利用Scripting API for WMI,必需援用 Microsoft WMI Scripting V1.1 Library
上面引见Scripting API For WMI的几个对象
SWbemLocator――用于获得SWbemServices对象,他代表了当地或近程盘算机上名字空间的一个毗连。
SWbemService――代表名字空间的一个毗连,可用于处置它的部件
SWbemObject――代表一个独自的类界说或一个对象实例
SWbemOjbectSet――包含SWbemObject的纠合
上面是DNS WMI Provider的几个对象
MicrosoftDNS_Zone――用于办理DNS办事器上的区域的类
MicrosoftDNS_AType,MicrosoftDNS_CNAMEType,MicrosoftDNS_MXType等等――办理DNS Server上的各类资本纪录
具体的参考请见MSDN,我用的是VS.NET2003带的MSDN
Scripting API for WMI的途径是 MSDN Library--设置和体系办理--Windows Management Instrumentation(WMI)--SDK文档--WMI Reference--Scripting API For WMI
DNS WMI Provider的途径是 MSDN Library--收集和目次办事--域名体系(DNS)--SDK文档--DNS WMI Provider--DNS WMI Provider Reference--DNS WMI Classes
上面是代码完成
需求援用Microsoft Scripting Runtime和Microsoft WMI Scripting V1.1 Library,只是示例了A、MX、和CName纪录的操作,还可以扩大其他资本纪录的操作,也能够加上区域的操作,参考MSDN就能够了
Class DNSController
Private objService As Object
Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long
Private Type OSVERSIONINFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128
osName As String
End Type
Private Function GetWindowsVersion() As OSVERSIONINFO
Dim ver As OSVERSIONINFO
ver.dwOSVersionInfoSize = 148
GetVersionEx ver
With ver
Select Case .dwPlatformId
Case 1
Select Case .dwMinorVersion
Case 0
.osName = "Windows 95"
Case 10
.osName = "Windows 98"
Case 90
.osName = "Windows Mellinnium"
End Select
Case 2
Select Case .dwMajorVersion
Case 3
.osName = "Windows NT 3.51"
Case 4
.osName = "Windows NT 4.0"
Case 5
If .dwMinorVersion = 0 Then
.osName = "Windows 2000"
ElseIf .dwMinorVersion = 1 Then
.osName = "Windows XP"
Else
.osName = "Windows 2003"
End If
End Select
Case Else
.osName = "Failed"
End Select
End With
GetWindowsVersion = ver
End Function
'判别操作体系,因为WMI在2003和2000上的完成略有差别,所以需求判别操作体系
Private Function IsWin2k3() As Boolean
Dim v As OSVERSIONINFO
v = GetWindowsVersion()
If v.osName = "Windows 2003" Then
IsWin2k3 = True
Else
IsWin2k3 = False
End If
End Function
'//
'// 毗连到一个DNS办事器
'//
'// 办事器称号,可所以盘算机名,也能够是IP
'// 毗连办事器所利用的用户名,假如是毗连本机,请利用""
'// 毗连办事器所利用的暗码,假如是毗连本机,请利用""
Public Function Connect(ByVal strServer As Variant, ByVal strUserName As Variant, ByVal strPassword As Variant, ByRef errMsg As Variant) As Variant
On Error GoTo ll
Connect = True
Err.Clear
Dim objLocator As WbemScripting.SWbemLocator
Set objLocator = CreateObject("WbemScripting.SWbemLocator")
Set objService = objLocator.ConnectServer(strServer, "root\microsoftdns", strUserName, strPassword)
objService.Security_.ImpersonationLevel = 3
Connect = True
Exit Function
ll: Connect = False
errMsg = "毛病 0x" & CStr(Hex(Err.Number)) & ",毗连办事器 " & strServer & " 时呈现毛病,详细信息是" & vbCrLf & Err.Description
Set objLocator = Nothing
Set objService = Nothing
Err.Clear
End Function
'//
'// 从办事器断开毗连
'//
Public Sub DisConnect()
Set objService = Nothing
End Sub
'//
'// 创立区域函数
'//
'// 区域称号
'// 区域保留的文件称号 通常为 "区域称号.dns"
'// 前往毛病信息
'// 前往操作是不是胜利
Public Function CreateZone(ByVal sZoneName As Variant, ByVal sDataFileName As Variant, ByRef errMsg As Variant) As Variant
Set objInst = SelectRR("MicrosoftDNS_Zone", " ContainerName=" & Chr(34) & sZoneName & Chr(34), errMsg)
If errMsg <> "" Then
CreateZone = False
Exit Function
End If
If objInst.Count > 0 Then
errMsg = "该区域已存在"
CreateZone = False
End If
Set objInst = Nothing
Dim oParams As New Dictionary
oParams.Add "ZoneName", sZoneName
'这是由于win2003和win2000体系中CreateZone函数的zoneType参数纷歧致 PrimaryZone的值在2000中是1,在2003中是0
If IsWin2k3() Then
zoneType = 0
Else
zoneType = 1
End If
oParams.Add "ZoneType", zoneType
CreateZone = Create("MicrosoftDNS_Zone", "CreateZone", oParams, errMsg)
Set oParams = Nothing
End Function
'//
'// 删除一个区域
'//
'// 要删除区域的域名
Public Function DeleteZone(ByVal sContainerName As Variant, ByRef errMsg As Variant) As Variant
DeleteZone = Delete("MicrosoftDNS_Zone", "ContainerName", sContainerName, errMsg)
End Function
'//
'// 添加A纪录
'//
'// 主机称号
'// 主机对应的IP
'// 地点区域的域名
Public Function CreateARecord(ByVal sHostName As Variant, ByVal sContainerName As Variant, ByVal sIPAddress As Variant, ByRef errMsg As Variant) As Variant
If sHostName = "" Then
sOwnerName = sContainerName
Else
sOwnerName = sHostName & "." & sContainerName
End If
Set objInst = SelectRR("MicrosoftDNS_AType", " ownerName=" & Chr(34) & sOwnerName & Chr(34), errMsg)
If errMsg <> "" Then
CreateARecord = False
Exit Function
End If
If objInst.Count > 0 Then
errMsg = "该纪录已存在"
CreateARecord = False
End If
Set objInst = Nothing
Dim oParams As New Dictionary
oParams.Add "ContainerName", sContainerName
oParams.Add "OwnerName", sOwnerName
oParams.Add "IPAddress", sIPAddress
CreateARecord = Create("MicrosoftDNS_AType", "CreateInstanceFromPropertyData", oParams, errMsg)
Set oParams = Nothing
End Function
'//
'// 修正A纪录信息
'//
'// 主机全名 例如说 www.mglz.net
'// 主机对应的IP
Public Function ModifyARecord(ByVal sOwnerName As Variant, ByVal sIPAddress As Variant, ByRef errMsg As Variant) As Variant
Dim oParams As New Dictionary
oParams.Add "IPAddress", sIPAddress
ModifyARecord = Modify("MicrosoftDNS_AType", "OwnerName", sOwnerName, "Modify", oParams, errMsg)
Set oParams = Nothing
End Function
'//
'// 删除A纪录纪录
'//
'// 主机全名 例如说 www.mglz.net
Public Function DeleteARecord(ByVal sOwnerName As Variant, ByRef errMsg As Variant) As Variant
DeleteARecord = Delete("MicrosoftDNS_AType", "OwnerName", sOwnerName, errMsg)
End Function
'//
'// 添加MX纪录
'//
'// 主机称号
'// 地点区域的域名
'// 要转向到的邮件办事器
'// 优先级
Public Function CreateMXRecord(ByVal sHostName As Variant, ByVal sContainerName As Variant, ByVal sMailServer As Variant, ByVal sPreference As Variant, ByRef errMsg As Variant) As Variant
If sHostName = "" Then
sOwnerName = sContainerName
Else
sOwnerName = sHostName & "." & sContainerName
End If
Set objInst = SelectRR("MicrosoftDNS_MXType", " ownerName=" & Chr(34) & sOwnerName & Chr(34), errMsg)
If errMsg <> "" Then
CreateMXRecord = False
Exit Function
End If
If objInst.Count > 0 Then
errMsg = "该纪录已存在"
CreateMXRecord = False
End If
Set objInst = Nothing
Dim oParams As New Dictionary
oParams.Add "ContainerName", sContainerName
If sHostName = "" Then
oParams.Add "OwnerName", sContainerName
Else
oParams.Add "OwnerName", sHostName & "." & sContainerName
End If
oParams.Add "Preference", sPreference
oParams.Add "MailExchange", sMailServer
CreateMXRecord = Create("MicrosoftDNS_MXType", "CreateInstanceFromPropertyData", oParams, errMsg)
Set oParams = Nothing
End Function
'//
'// 修正MX纪录
'//
'// 主机全名 例如说 www.mglz.net
'// 要转向到的邮件办事器
'// 优先级
Public Function ModifyMXRecord(ByVal sOwnerName As Variant, ByVal sMailServer As Variant, ByVal sPreference As Variant, ByRef errMsg As Variant) As Variant
Dim oParams As New Dictionary
oParams.Add "MailExchange", sMailServer
oParams.Add "Preference", sPreference
ModifyMXRecord = Modify("MicrosoftDNS_MXType", "OwnerName", sOwnerName, "Modify", oParams, errMsg)
Set oParams = Nothing
End Function
'//
'// 删除MX纪录
'//
'// 主机全名 例如说 www.mglz.net
Public Function DeleteMXRecord(ByVal sOwnerName As Variant, ByRef errMsg As Variant) As Variant
DeleteMXRecord = Delete("MicrosoftDNS_MXType", "OwnerName", sOwnerName, errMsg)
End Function
'//
'// 添加别号
'//
'// 别号
'// 地点区域的域名
'// 方针主机称号
Public Function CreateCName(ByVal sHostName As Variant, ByVal sContainerName As Variant, ByVal sPrimaryName As Variant, ByRef errMsg As Variant) As Variant
If sHostName = "" Then
sOwnerName = sContainerName
Else
sOwnerName = sHostName & "." & sContainerName
End If
Set objInst = SelectRR("MicrosoftDNS_CNAMEType", " ownerName=" & Chr(34) & sOwnerName & Chr(34), errMsg)
If errMsg <> "" Then
CreateCName = False
Exit Function
End If
If objInst.Count > 0 Then
errMsg = "该纪录已存在"
CreateCName = False
End If
Set objInst = Nothing
Dim oParams As New Dictionary
oParams.Add "ContainerName", sContainerName
If sHostName = "" Then
oParams.Add "OwnerName", sContainerName
Else
oParams.Add "OwnerName", sHostName & "." & sContainerName
End If
oParams.Add "PrimaryName", sPrimaryName
CreateCName = Create("MicrosoftDNS_CNAMEType", "CreateInstanceFromPropertyData", oParams, errMsg)
Set oParams = Nothing
End Function
'//
'// 修正别号
'//
'// 别号全称 例如说 www.mglz.net
'// 方针主机称号
Public Function ModifyCName(ByVal sOwnerName As Variant, ByVal sPrimaryName As Variant, ByRef errMsg As Variant) As Variant
Dim oParams As New Dictionary
oParams.Add "PrimaryName", sPrimaryName
ModifyCName = Modify("MicrosoftDNS_CNAMEType", "OwnerName", sOwnerName, "Modify", oParams, errMsg)
Set oParams = Nothing
End Function
'//
'// 删除别号
'//
'// 别号全称 例如说 www.mglz.net
Public Function DeleteCName(ByVal sOwnerName As Variant, ByRef errMsg As Variant) As Variant
DeleteCName = Delete("MicrosoftDNS_CNAMEType", "OwnerName", sOwnerName, errMsg)
End Function
Private Function Create(ByVal sTableName As String, ByVal MethodName As String, ByRef oParms As Dictionary, ByRef errMsg As Variant) As Boolean
On Error GoTo ll
Set oProcess = objService.Get(sTableName)
Set oInParams = oProcess.Methods_(MethodName).InParameters.SpawnInstance_()
For Each Key In oParms.Keys
oInParams.Properties_.Item(Key).Value = CStr(oParms.Item(Key))
Next
objService.ExecMethod sTableName, MethodName, oInParams
errMsg = ""
Create = True
Exit Function
ll:
Create = False
errMsg = Err.Description
End Function
Private Function Modify(ByVal sTableName As String, ByVal sFieldName As String, ByVal sFieldValue As String, ByVal MethodName As String, ByRef oParams As Dictionary, ByRef errMsg As Variant) As Boolean
Dim sQuery As String
sQuery = "SELECT * FROM " & sTableName & " WHERE " & sFieldName & " = '" & sFieldValue & "'"
On Error GoTo ll
Set objInst = objService.ExecQuery(sQuery)
For Each o In objInst
Set oInParams = o.Methods_(MethodName).InParameters.SpawnInstance_()
For Each Key In oParams.Keys
oInParams.Properties_.Item(Key).Value = CStr(oParams.Item(Key))
Next
o.ExecMethod_ MethodName, oInParams
Next
errMsg = ""
Modify = True
Exit Function
ll:
Modify = False
errMsg = Err.Description
End Function
Private Function Delete(ByVal sTableName As String, ByVal sFieldName As String, ByVal sFieldValue As String, ByRef errMsg As Variant) As Boolean
Dim sQuery As String
sQuery = "SELECT * FROM " & sTableName & " WHERE " & sFieldName & " = '" & sFieldValue & "'"
On Error GoTo ll
Set objInst = objService.ExecQuery(sQuery)
For Each o In objInst
o.Delete_
Next
errMsg = ""
Delete = True
Exit Function
ll:
Delete = False
errMsg = Err.Description
End Function
Private Function SelectRR(ByVal recordType As String, ByVal sFilterExpression As String, ByRef errMsg As Variant) As Object
On Error GoTo ll
errMsg = ""
sql = "Select * from " & recordType
If sFilterExpression <> "" Then
sql = sql & " where " & sFilterExpression
End If
Set SelectRR = objService.ExecQuery(sql)
errMsg = ""
Exit Function
ll: errMsg = Err.Description
Set SelectRR = Nothing
Err.Clear
End Function
end Class
对于中小型web应用来说,php有很强的竞争力,linux+apache+mysql+php(lamp)的组合几乎可以胜任绝大多数网站的解决方案,对于大型应用来讲,对于系统架构要求更高,需要有成熟的框架支持,jsp的struts是个不错的框架,国内介绍它的资料也非常多,应用逐渐广泛起来。asp就不用说了, |
|