计算机加入域或工作组的实例
Win32_ComputerSystem 类别代表在 Win32 环境中操作的计算机系统。
Imports System Imports System.Management Imports System.Windows.Forms
Namespace WMISample
Public Class CallWMIMethod
Public Overloads Shared Function Main() As Integer
Try
Dim classInstance As New ManagementObject( _ "root\CIMV2", _ "Win32_ComputerSystem.ReplaceKeyPropery='ReplaceKeyPropertyValue'", _ Nothing)
' Obtain [in] parameters for the method Dim inParams As ManagementBaseObject = _ classInstance.GetMethodParameters("JoinDomainOrWorkgroup")
' Add the input parameters.
' Execute the method and obtain the return values. Dim outParams As ManagementBaseObject = _ classInstance.InvokeMethod("JoinDomainOrWorkgroup", inParams, Nothing)
' List outParams 更多实例 关注lob.cn 乐博网 Console.WriteLine("Out parameters:") Console.WriteLine("ReturnValue: {0}", outParams("ReturnValue"))
Catch err As ManagementException
MessageBox.Show("An error occurred while trying to execute the WMI method: " & err.Message) End Try End Function End Class End Namespace
乐博网附说明:
JoinDomainOrWorkgroup 方法将计算机系统加入到一个域或工作组。该方法仅用于 Windows 2000 和更高版本平台上的域重命名。该方法可以返回下列值: 0 – 成功。 其它 – 关于上面所列以外的整数值,请参阅 Win32 错误代码文档。 注意: 如果将一台计算机从域移动到工作组,在运行此方法将其加入工作组之前计算机必须先从域中删除。 当域计算机连接到其 IWbemServices ptr 上的 winmgmt(即在获取 IWbemServices 接口的调用中)或 SetProxyBlanket 时,Password 和 Username 必须使用高级验证级别(即不低于 RPC_C_AUTHN_LEVEL_PKT_PRIVACY)。如果对于 winmgmt 来说,它们是本地计算机,这一点不是问题,因为其验证级别不仅与 RPC_C_AUTHN_LEVEL_PKT_PRIVACY 具有相同级别,而且其客户端请求从不通过连接到达 winmgmt。 如果 Password 和 Username 保留为空字符,提供程序不会在意。 如果提供程序认为验证级别太低并且指定了 Password 和 Username,则返回 WBEM_E_ENCRYPTED_CONNECTION_REQUIRED。 |