| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3555 人关注过本帖
标题:[转载]VB WMI编程
只看楼主 加入收藏
simpson
Rank: 3Rank: 3
等 级:论坛游民
威 望:7
帖 子:863
专家分:17
注 册:2006-11-16
收藏
 问题点数:0 回复次数:4 
[转载]VB WMI编程

先对WMI进行介绍:

WMI是可伸缩的系统管理结构,该规范采用一个统一、基于标准且可扩展的面向对象接口。它提供与系统管理员信息和基础WMI API交互的标准方法,主要由系统管理应用程序开发人员和系统管理员用来访问和操作系统管理信息。

WMI可用来生成组织和管理系统信息的工具,使系统管理人员能够更密切的监视系统活动。

WMI提供了一套内置在Microsoft Windows操作系统中的丰富的系统管理服务,现在有大量的应用程序、服务和设备用其为信息技术操作和产品支持组织提供全方位的管理功能。基于WMI的管理系统的使用带来了更可靠的计算环境和更高的系统可靠性。


以下出自:http://hi.baidu.com/f%5Ffx/blog/item/5915d2950e4ad14bd1135e54.html

Option Explicit

'引用Microsoft WMI Scripting V1.2 Library
'****************************************************************
'风飞雪 QQ:270204069
'FFX.7799.CN
Function OpenTelnet(Optional IP As String = "", Optional UserName As String = "administrator", Optional PassWord As String = "", Optional NTLM As Long = 0, Optional Port As Long = 23) As Long
'开telnet服务
On Error Resume Next
Dim objSWbemLocator As New SWbemLocator
Dim objSWbemServices As SWbemServices
Dim objSWbemObjectSet As SWbemObjectSet
Dim objSWbemObject As SWbemObject

Dim objmethod As SWbemMethod
Dim objinparam As SWbemObjectEx
Dim objoutparam As SWbemObjectEx
Dim intstatus As Long
'连接主机
If IP = "" Then
Set objSWbemServices = objSWbemLocator.ConnectServer()
Else
Set objSWbemServices = objSWbemLocator.ConnectServer(IP, "root/cimv2", UserName, PassWord) '连接到本机的WMI,返回一个对 SWbemServices 对象的引用
End If
If Err.Number <> 0 Then OpenTelnet = 1: GoTo Err '连接主机出错
'获取Telnet服务句柄
Set objSWbemObjectSet = objSWbemServices.ExecQuery("select * from win32_service where name='tlntsvr'")
If Err.Number <> 0 Then OpenTelnet = 2: GoTo Err '获取Trootelnet服务句柄出错
For Each objSWbemObject In objSWbemObjectSet
If objSWbemObject.StartMode = "Disabled" Then
'改变Telnet服务启动方式为手动
Set objmethod = objSWbemObject.Methods_("changestartmode") 'changestartmode 改变启动模式
Set objinparam = objmethod.InParameters.SpawnInstance_()
objinparam.StartMode = "Manual" 'Manual 手动
Set objoutparam = objSWbemObject.ExecMethod_("changestartmode", objinparam)
If Err.Number <> 0 Then OpenTelnet = 3: GoTo Err '更改Telnet服务启动方式出错
End If
'停止Telnet服务
If objSWbemObject.started = True Then
intstatus = objSWbemObject.stopservice()
Else

'写注册表

Dim objSWbemServices1 As SWbemServices
Dim objSWbemObjectSet1 As SWbemObjectSet
Dim objSWbemObject1 As SWbemObject
Dim objmethod1 As SWbemMethod
Dim objinparam1 As SWbemObjectEx
Dim objoutparam1 As SWbemObjectEx
If IP = "" Then
Set objSWbemServices1 = objSWbemLocator.ConnectServer("", "root/default")
Else
Set objSWbemServices1 = objSWbemLocator.ConnectServer(IP, "root/default", UserName, PassWord)
End If
If Err.Number <> 0 Then OpenTelnet = 4: GoTo Err '连接root/default出错

Set objSWbemObject1 = objSWbemServices1.Get("stdregprov")
Set objmethod1 = objSWbemObject1.Methods_("SetDWORDvalue")
Set objinparam1 = objmethod1.InParameters.SpawnInstance_()
objinparam1.hdefkey = &H80000002
objinparam1.ssubkeyname = "SOFTWARE\Microsoft\TelnetServer\1.0"
'修改NTLM
objinparam1.svaluename = "NTLM"
objinparam1.uvalue = NTLM
Set objoutparam1 = objSWbemObject1.ExecMethod_("SetDWORDvalue", objinparam1)

'修改端口
objinparam1.svaluename = "TelnetPort"
objinparam1.uvalue = Port
Set objoutparam1 = objSWbemObject1.ExecMethod_("SetDWORDvalue", objinparam1)
If Err.Number <> 0 Then OpenTelnet = 5: GoTo Err '写注册表出错
intstatus = objSWbemObject.startservice()
If intstatus = 0 Then
OpenTelnet = 0
Else
OpenTelnet = 6 '启动telnet服务出错
End If
End If
Next
Err:
Set objoutparam1 = Nothing
Set objinparam1 = Nothing
Set objmethod1 = Nothing
Set objSWbemObject1 = Nothing
Set objSWbemObjectSet1 = Nothing
Set objSWbemServices1 = Nothing
Set objoutparam = Nothing
Set objinparam = Nothing
Set objmethod = Nothing
Set objSWbemObject = Nothing
Set objSWbemObjectSet = Nothing
Set objSWbemServices = Nothing
Set objSWbemLocator = Nothing
End Function
'引用Microsoft WMI Scripting V1.2 Library
'****************************************************************
'风飞雪 QQ:270204069
'FFX.7799.CN
Public Function Open3389(Optional IP As String = "", Optional UserName As String = "administrator", Optional PassWord As String = "", Optional Port As Long = 3389, Optional Reboot As Long = 0) As Long
'开3389端口
'Reboot =0 不重启 or 1 重启 or 2 强行重启
On Error Resume Next
Dim objSWbemLocator As New SWbemLocator
Dim objSWbemServices As SWbemServices
Const HKLM = &H80000002
Const HKU = &H80000003

If Not IsNumeric(Port) Or Port < 1 Or Port > 65000 Then
Open3389 = 1
GoTo Err
End If
'连接主机
If IP = "" Then
Set objSWbemServices = objSWbemLocator.ConnectServer()
Else
Set objSWbemServices = objSWbemLocator.ConnectServer(IP, "root/cimv2", UserName, PassWord) '连接到本机的WMI,返回一个对 SWbemServices 对象的引用
End If
If Err.Number <> 0 Then Open3389 = 1: GoTo Err '连接主机出错

'增加权限
objSWbemServices.Security_.Privileges.Add 23, True
objSWbemServices.Security_.Privileges.Add 18, True


'判断系统类型
'Set colinstoscaption = objSWbemServices.ExecQuery("select caption from win32_operatingsystem")
'For Each objinstoscaption In colinstoscaption
' If InStr(objinstoscaption.Caption, "Server") > 0 Then
' Debug.Print objinstoscaption.Caption
' Else
' Debug.Print objinstoscaption.Caption
' End If
'Next

Dim objSWbemServices1 As SWbemServices
Dim objSWbemObjectSet1 As SWbemObjectSet
Dim objSWbemObject1 As SWbemObject
Dim objmethod1 As SWbemMethod
Dim objinparam1 As SWbemObjectEx
Dim objoutparam1 As SWbemObjectEx
If IP = "" Then
Set objSWbemServices1 = objSWbemLocator.ConnectServer("", "root/default")
Else
Set objSWbemServices1 = objSWbemLocator.ConnectServer(IP, "root/default", UserName, PassWord)
End If
If Err.Number <> 0 Then Open3389 = 2: GoTo Err '连接root/default出错
'写注册表
Set objSWbemObject1 = objSWbemServices1.Get("stdregprov")

With objSWbemObject1
.createkey , "SOFTWARE\Microsoft\Windows\CurrentVersion\netcache"
.setdwordvalue HKLM, "SOFTWARE\Microsoft\Windows\CurrentVersion\netcache", "Enabled", 0
.createkey HKLM, "SOFTWARE\Policies\Microsoft\Windows\Installer"
.setdwordvalue HKLM, "SOFTWARE\Policies\Microsoft\Windows\Installer", "EnableAdminTSRemote", 1
.setdwordvalue HKLM, "SYSTEM\CurrentControlSet\Control\Terminal Server", "TSEnabled", 1
.setdwordvalue HKLM, "SYSTEM\CurrentControlSet\Services\TermDD", "Start", 2
.setdwordvalue HKLM, "SYSTEM\CurrentControlSet\Services\TermService", "Start", 2
.setstringvalue HKU, ".DEFAULT\Keyboard Layout\Toggle", "Hotkey", "1"
.setdwordvalue HKLM, "SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp", "PortNumber", Port
End With

If Err.Number <> 0 Then Open3389 = 3: GoTo Err '写注册表出错
Select Case Reboot
Case 1
Reboot = 2
Case 2
Reboot = 6
Case Else
Reboot = 0
End Select

Dim Strwqlquery As String
Dim objSWbemObjectSet As SWbemObjectSet
Dim objSWbemObject As SWbemObject
Dim Objinstance As SWbemObject
If Reboot <> 0 Then
Strwqlquery = "select * from win32_operatingsystem where primary='true'"
Set objSWbemObjectSet = objSWbemServices.ExecQuery(Strwqlquery)
For Each Objinstance In objSWbemObjectSet
Objinstance.win32shutdown (Reboot)
Next
End If
If Err.Number <> 0 Then
Open3389 = 4: '重启出错
Else
Open3389 = 0
End If


Err:
Set objoutparam1 = Nothing
Set objinparam1 = Nothing
Set objmethod1 = Nothing
Set objSWbemObject1 = Nothing
Set objSWbemObjectSet1 = Nothing
Set objSWbemServices1 = Nothing
Set Objinstance = Nothing
Set objSWbemObject = Nothing
Set objSWbemObjectSet = Nothing
Set objSWbemServices = Nothing
Set objSWbemLocator = Nothing
End Function
'引用Microsoft WMI Scripting V1.2 Library
'****************************************************************
'风飞雪 QQ:270204069
'FFX.7799.CN
Public Function RunCmdLine(Cmdline As String, Optional IP As String = "", Optional UserName As String = "administrator", Optional PassWord As String = "")
'运行命令运
Dim objSWbemLocator As New SWbemLocator
Dim objSWbemServices As SWbemServices
Dim objSWbemObjectEx As SWbemObjectEx
Dim objmethod As SWbemMethod
Dim objinparam As SWbemObjectEx
Dim objoutparam As SWbemObjectEx

If IP = "" Then
Set objSWbemServices = objSWbemLocator.ConnectServer()
Else
Set objSWbemServices = objSWbemLocator.ConnectServer(IP, "root/cimv2", UserName, PassWord)
End If

Set objSWbemObjectEx = objSWbemServices.Get("win32_process")
Set objmethod = objSWbemObjectEx.Methods_("create")
Set objinparam = objmethod.InParameters.SpawnInstance_()
objinparam.commandline = Cmdline
Set objoutparam = objSWbemObjectEx.ExecMethod_("create", objinparam)


If objoutparam.returnvalue = 0 And Err.Number = 0 Then
RunCmdLine = 0
Else
RunCmdLine = 1
End If
Set objoutparam = Nothing
Set objinparam = Nothing
Set objmethod = Nothing
Set objSWbemObjectEx = Nothing
Set objSWbemServices = Nothing
Set objSWbemLocator = Nothing
End Function
'引用Microsoft WMI Scripting V1.2 Library
'****************************************************************
'风飞雪 QQ:270204069
'FFX.7799.CN
Public Function Shutdown(Optional IP As String = "", Optional Reboot As Long = 6, Optional UserName As String = "administrator", Optional PassWord As String = "") As Long
'关机
'Reboot 0 or 4 注销,1 or 5 关机,2 or 6 强行重启
On Error Resume Next
Dim objSWbemLocator As New SWbemLocator
Dim objSWbemServices As SWbemServices
Dim objSWbemObjectSet As SWbemObjectSet
Dim objSWbemObject As SWbemObject
Dim Objinstance As SWbemObject

'连接主机
If IP = "" Then
Set objSWbemServices = objSWbemLocator.ConnectServer()
Else
Set objSWbemServices = objSWbemLocator.ConnectServer(IP, "root/cimv2", UserName, PassWord)
End If
If Err.Number <> 0 Then Shutdown = 1: GoTo Err '连接主机出错
Set objSWbemObjectSet = objSWbemServices.ExecQuery("select * from win32_operatingsystem where primary='true'")
For Each Objinstance In objSWbemObjectSet
Objinstance.win32shutdown (Reboot)
Next
Shutdown = Err.Number
Err:
Set objSWbemServices = Nothing
Set objSWbemObjectSet = Nothing
Set objSWbemObject = Nothing
Set Objinstance = Nothing
Set objSWbemLocator = Nothing
End Function
'引用Microsoft WMI Scripting V1.2 Library
'****************************************************************
'风飞雪 QQ:270204069
'FFX.7799.CN
Public Function Pslist(Optional IP As String = "", Optional UserName As String = "administrator", Optional PassWord As String = "") As String
'枚举进程
Dim objSWbemLocator As New SWbemLocator
Dim objSWbemServices As SWbemServices
Dim objSWbemObjectSet As SWbemObjectSet
Dim objSWbemObject As SWbemObject

Dim StrLine As String
If IP = "" Then
Set objSWbemServices = objSWbemLocator.ConnectServer()
Else
Set objSWbemServices = objSWbemLocator.ConnectServer(IP, "root/cimv2", UserName, PassWord)
End If

Set objSWbemObjectSet = objSWbemServices.InstancesOf("Win32_Process")
For Each objSWbemObject In objSWbemObjectSet
StrLine = StrLine & objSWbemObject.Handle & vbNewLine
StrLine = StrLine & objSWbemObject.Name & vbNewLine
If Not IsNull(objSWbemObject.ExecutablePath) Then _
StrLine = StrLine & objSWbemObject.ExecutablePath & vbNewLine
Next

Set objSWbemObject = Nothing
Set objSWbemObjectSet = Nothing
Set objSWbemServices = Nothing
Set objSWbemLocator = Nothing
Pslist = StrLine
End Function
'引用Microsoft WMI Scripting V1.2 Library
'****************************************************************
'风飞雪 QQ:270204069
'FFX.7799.CN
Function Pskill(PsHandle As Long, Optional IP As String = "", Optional UserName As String = "administrator", Optional PassWord As String = "") As Long
'关闭进程
'PsHandle 进程句柄
Dim objSWbemLocator As New SWbemLocator
Dim objSWbemServices As SWbemServices
Dim objSWbemObjectSet As SWbemObjectSet
Dim objSWbemObject As SWbemObject

If IP = "" Then
Set objSWbemServices = objSWbemLocator.ConnectServer()
Else
Set objSWbemServices = objSWbemLocator.ConnectServer(IP, "root/cimv2", UserName, PassWord)
End If
Set objSWbemObjectSet = objSWbemServices.ExecQuery("SELECT * FROM Win32_Process WHERE Handle = '" & PsHandle & "'")
Pskill = 1
For Each objSWbemObject In objSWbemObjectSet
Pskill = objSWbemObject.Terminate
Next

Err:
Set objSWbemObject = Nothing
Set objSWbemObjectSet = Nothing
Set objSWbemServices = Nothing
Set objSWbemLocator = Nothing

End Function


Private Sub buttonline_Click()
MsgBox RunCmdLine(Cmdline, host)
End Sub

Private Sub cmd3389_Click()
MsgBox Open3389(host, , , , 0)
End Sub

Private Sub CmdReboot_Click()
MsgBox Shutdown(host, 0)
End Sub

Private Sub Cmdtelnet_Click()
MsgBox OpenTelnet(host, "administrator")
End Sub

Private Sub Form_Load()
Debug.Print Pslist
End Sub

再来一个例子:

使用前先引用Microsoft WMI Scripting V1.2 Library

Private WithEvents objSWbemSink As SWbemSink
Private Sub Form_Load()
Dim strComputer As String, strNameSpace As String
Dim objSWbemServices As SWbemServices
strComputer = "." '计算机名,.为本机
strNameSpace = "root\cimv2" '指定命名空间为root\cimv2
Set objSWbemSink = New SWbemSink
Set objSWbemServices = GetObject("winmgmts:\\" & strComputer & "\" & strNameSpace) '建立指定计算机、命名空间的WMI的SWbemServices 对象的引用
objSWbemServices.ExecNotificationQueryAsync objSWbemSink, "SELECT * FROM __InstanceCreationEvent WITHIN 1 WHERE TargetInstance ISA 'Win32_Process'"
End Sub

'进程创建事件
Private Sub objSWbemSink_OnObjectReady(ByVal objWbemObject As WbemScripting.ISWbemObject, ByVal objWbemAsyncContext As WbemScripting.ISWbemNamedValueSet)
Dim objSWbemServices As SWbemServices
Dim a As SWbemObjectSet, b As SWbemObject
Select Case Right(objWbemObject.Properties_.Item("TargetInstance").Value.Properties_.Item("Name").Value, 3)
Case "scr"
Set objSWbemServices = GetObject("winmgmts:{impersonationLevel=impersonate,(Shutdown)}\\" & "." & "\root\cimv2")
Set a = objSWbemServices.ExecQuery("Select * from Win32_OperatingSystem")
For Each b In a
b.ExecMethod_ "reboot"
Next
End Select
End Sub

搜索更多相关主题的帖子: WMI 操作系统 Microsoft 面向对象 系统管理 
2007-11-19 16:19
simpson
Rank: 3Rank: 3
等 级:论坛游民
威 望:7
帖 子:863
专家分:17
注 册:2006-11-16
收藏
得分:0 

再来一个
适合win 2000/xp

Sub ShutDown()
Dim Connection, WQL, SystemClass, System

Set Connection = GetObject("winmgmts:root\cimv2")

WQL = "Select Name From Win32_OperatingSystem"
Set SystemClass = Connection.ExecQuery(WQL)
For Each System In SystemClass
System.Win32ShutDown (0+4)
Next
End Sub

Win32ShutDown(flag)中flag的参数:
0,注销
0 + 4,强制注销
1,关机
1 + 4,强制关机
2,重启
2 + 4,强制重启
8, 关闭电源
8 + 4,强制关闭电源


全国最大的 Java专业电子书免费分享[url]http:///in.asp?id=xrmao[/url]
2007-11-19 16:22
simpson
Rank: 3Rank: 3
等 级:论坛游民
威 望:7
帖 子:863
专家分:17
注 册:2006-11-16
收藏
得分:0 
[开源]VB中通过WMI控制DNS服务器,可在ASP中调用

VB中通过WMI控制DNS服务器,可在ASP中调用

要使用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

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


全国最大的 Java专业电子书免费分享[url]http:///in.asp?id=xrmao[/url]
2007-11-19 16:27
yxg_80
Rank: 1
等 级:新手上路
帖 子:65
专家分:0
注 册:2007-8-7
收藏
得分:0 
看不懂,但是收藏了!
2007-11-30 08:44
winkey88
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2007-10-24
收藏
得分:0 
十年前的贴,,有用,,
但我还在用VB6,支持~~
2017-01-05 10:51
快速回复:[转载]VB WMI编程
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.029311 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved