Option Explicit
' wbemChangeFlagEnum Setting
const UpdateOnly = 1
const CreateOnly = 2
' Basic WMI operation - Create
' Sample to show MSBTS_HostSetting instance creation
Sub CreateHost (HostName, HostType, NTGroupName, AuthTrusted)
On Error Resume Next
Dim objLocator, objService, objHostSetting, objHS
' Connects to local server WMI Provider BizTalk namespace
Set objLocator = Createobject ("wbemScripting.SWbemLocator")
Set objService = objLocator.ConnectServer(".", "root/MicrosoftBizTalkServer")
' Get WMI class MSBTS_HostSetting
Set objHostSetting = objService.Get ("MSBTS_HostSetting")
Set objHS = objHostSetting.SpawnInstance_
objHS.Name = HostName
objHS.HostType = HostType
objHS.NTGroupName = NTGroupName
objHS.AuthTrusted = AuthTrusted
' Create instance
objHS.Put_(CreateOnly)
CheckWMIError
wscript.echo "Host - " & HostName & " - has been created successfully"
end Sub
' Basic WMI operation - Update
' Sample to show MSBTS_HostSetting instance update
Sub UpdateHost (HostName, NTGroupName, AuthTrusted)
On Error Resume Next
Dim objLocator, objService, objHS
' Connects to local server WMI Provider BizTalk namespace
Set objLocator = Createobject ("wbemScripting.SWbemLocator")
Set objService = objLocator.ConnectServer(".", "root/MicrosoftBizTalkServer")
' Look for WMI Class MSBTS_HostSetting with name equals HostName value
Set objHS = objService.Get("MSBTS_HostSetting.Name='" & HostName & "'")
objHS.NTGroupName = NTGroupName
objHS.AuthTrusted = AuthTrusted
' Update instance properties
objHS.Put_(UpdateOnly)
' Check for error condition before continuing.
CheckWMIError
wscript.echo "Host - " & HostName & " - has been updated successfully"
end Sub
' Basic WMI operation - Delete
' Sample to show MSBTS_HostSetting instance deletion
Sub DeleteHost (HostName)
On Error Resume Next
Dim objLocator, objService, objHS
' Connects to local server WMI Provider BizTalk namespace
Set objLocator = Createobject ("wbemScripting.SWbemLocator")
Set objService = objLocator.ConnectServer(".", "root/MicrosoftBizTalkServer")
' Look for WMI Class MSBTS_HostSetting with name equals HostName value
Set objHS = objService.Get("MSBTS_HostSetting.Name='" & HostName & "'")
' Delete instance
objHS.Delete_
' Check for error condition before continuing.
CheckWMIError
wscript.echo "Host - " & HostName & " - has been deleted sucessfully"
end Sub
'This subroutine deals with all errors using the WbemScripting object. Error descriptions
'are returned to the user by printing to the console.
Sub CheckWMIError()
If Err <> 0 Then
On Error Resume Next
Dim strErrDesc: strErrDesc = Err.Description
Dim ErrNum: ErrNum = Err.Number
Dim WMIError : Set WMIError = CreateObject("WbemScripting.SwbemLastError")
If ( TypeName(WMIError) = "Empty" ) Then
wscript.echo strErrDesc & " (HRESULT: " & Hex(ErrNum) & ")."
Else
wscript.echo WMIError.Description & "(HRESULT: " & Hex(ErrNum) & ")."
Set WMIError = nothing
End If
wscript.quit 0
End If
End Sub