Created
August 10, 2009 08:32
-
-
Save steefjan/165085 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Option Explicit | |
' wbemChangeFlagEnum Setting | |
const UpdateOnly = 1 | |
const CreateOnly = 2 | |
' HostType | |
const InProcess = 1 | |
const Isolated = 2 | |
CreateHost "Processing_Host", InProcess, "LAB\BizTalk Application Users", False, False, False, True | |
' Basic WMI operation - Create | |
' Sample to show MSBTS_HostSetting instance creation | |
Sub CreateHost (HostName, HostType, NTGroupName, AuthTrusted, Isdefault, IsHost32BitOnly, HostTracking ) | |
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 | |
objHS.Isdefault = IsDefault | |
objHS.IsHost32BitOnly = IsHost32BitOnly | |
objHS.HostTracking = HostTracking | |
' Create instance | |
objHS.Put_(CreateOnly) | |
CheckWMIError | |
wscript.echo "Host - " & HostName & " - has been created successfully" | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment