'======================================================================================= ' ' Phase I: This script is for saving/restoring NCS-WMI settings to/from a text file. ' Phase I limited to restoration of settings to same network adapter on same system ' ' Author: Jian Xu at NQL/Microsoft Automation Development Team ' Date: Sept. 20, 2002 ' '======================================================================================= ' ' Phase II: Script updated to allow settings restore to similar network adapter ' Compatibility is determined by existing network speed and capabilities of adapter settings ' ' Author: Carolyn Wyborny LAD RIGhT Team ' Date: October 29, 2002 ' '======================================================================================== ' This new version of Savres corrects 2 bugs in previous script: ' DCS #27710: failure to save configuration if team is renamed. This was corrected in several places ' using IsATeam property instead of the Caption of the team. ' DCS #27932: failure to restore more than 1 vlan under a team. This was corrected in ApplyTeamSettings ' variable numVLANs was not initialized correctly. ' Also the SaveSettings Sub has been rewritten in a more modular way. ' ' Author: Sebastien Michelet ' Date: March 27, 2003 '======================================================================================== Option Explicit Dim colArgs, strSettingsFile, SValueSet, SessionObject, NetServiceObject Dim strIfSetFile, strFileName, strSave, strChoices, strInput, bError, strNetSerObjPath Dim strSettingName, strFname, index, bChanged, bUserInput, bModified, NetServiceSet Dim totalAdapters, totalTeams, existTotalAdapters, bNewTeam, ServiceObject, FinalTargetObj Dim AdapterSets, AdapterObj, wbemServices, bCompat, strComputer, bHasTeamOrVLAN Dim bMisMatch, bSelected, strSettingsIndex, strCapabilities, strAdapterName Dim arrPrivDesc(), arrTeamPrivDesc(), Adapters(), Captions(), Teams() Dim VLANObjSet, VLANObj, TeamsObjSet, TeamObj Const maxAdapterTeamVLANs = 64 Const maxSettings = 1000 Const DefaultFileName = "WmiConf.txt" Set colArgs = WScript.Arguments strComputer = "." bHasTeamOrVLAN = FALSE ' Check submitted arguments, show Usage for no arguments, ? or help arguments If (WScript.Arguments.Count = 0) Then PrintUsage() Else If (WScript.Arguments(0) = "?" ) OR (LCase(WScript.Arguments(0)) = "help") Then PrintUsage() Else ' Assign variables after determining what combination of options have been submitted If WScript.Arguments.Count = 1 Then strIfSetFile = "FALSE" If LCase(WScript.Arguments(0)) = "save" Then strSave = "TRUE" ElseIf LCase(WScript.Arguments(0)) = "restore" Then strSave = "FALSE" End If Else If LCase(WScript.Arguments(0)) = "save" Then strSave = "TRUE" ElseIf LCase(WScript.Arguments(0)) = "restore" Then strSave = "FALSE" End If If LCase(WScript.Arguments(1)) = "default" Then strIfSetFile = "FALSE" Else strIfSetFile = "TRUE" End If End If 'Execute Save or Restore on what data user submitted, depending on the arguments set above If (strIfSetFile = "FALSE") Then strSettingsFile = defaultFileName If strSave = "TRUE" Then WScript.Echo "Executing Save on local computer with " & strSettingsFile SaveSettings(strSettingsFile) ElseIf strSave = "FALSE" Then WScript.Echo "Executing Restore on local computer with " & strSettingsFile RestoreSettings(strSettingsFile) Else WScript.Echo "Unrecognized keyword: " & WScript.Arguments(0) & ". Keyword must be 'save' or 'restore' only." End If Else strSettingsFile = WScript.Arguments(1) If strSave = "TRUE" Then WScript.Echo "Executing Save on local computer with " & strSettingsFile SaveSettings(strSettingsFile) ElseIf strSave = "FALSE" Then WScript.Echo "Executing Restore on local computer with " & strSettingsFile RestoreSettings(strSettingsFile) Else WScript.Echo "Unrecognized keyword: " & WScript.Arguments(0) & ". Keyword must be 'save' or 'restore' only." End If End If End If End If '======================================================================================= ' ' Sub: PrintUsage() ' '======================================================================================= Sub PrintUsage() WScript.Echo "Intel(R) SavRes.vbs version 1.0 " WScript.Echo "Copyright (C) Intel, Inc. 2002. All rights reserved." WScript.Echo "" WScript.Echo " Usage: savres.vbs keywords default/settingsfile" WScript.Echo " Keywords are required and are 'save' or 'restore' only." WScript.Echo " Settings file can be the keyword 'default' or an explicit file name." WScript.Echo " Settings filename can include the file path." WScript.Echo " Default filename is WMIConf.txt, saved to the current directory." WScript.Echo " Default filename is used if no settings filename is given or" WScript.Echo " the keyword 'default' is used." End Sub '======================================================================================= ' ' Sub: SaveSettings(ByVal strFname) ' Save Adapter's, team's and VLAN's info. and settings info. to a text file. ' Save Adapter's compatiblity settings. ' '======================================================================================= Sub SaveSettings(byVal strFileName) dim colNetDevices dim objNetDevice,objFile dim wbemServices dim DeviceIndex dim colTeams dim objTeam 'Create a configuration file Set objFile=CreateConfigFile(strFileName) objFile.WriteLine "*** NEW PROSET Configuration Save Data ***" objFile.WriteLine "*** Date " & Date & " Time " & Time() & " ***" objFile.WriteLine "**********************************************" objFile.WriteLine "" 'Get all instances from IANet_EthernetAdapter (Adapters and Teams) Set wbemServices = GetObject("winmgmts://./root/IntelNcs") Set colNetDevices = wbemServices.InstancesOf("IANet_EthernetAdapter") 'Save Adapters and Team Settings Set DeviceIndex=0 For each objNetDevice in colNetDevices DeviceIndex=DeviceIndex + 1 objFile.WriteBlankLines(1) if objNetDevice.IsATeam=TRUE Then 'Save Team specific info SaveTeamInfo objFile, objNetDevice, DeviceIndex, wbemServices Else 'Save Adapter specific info SaveAdapterInfo objFile, objNetDevice, DeviceIndex End If 'Save info common to adapters and teams SaveAdvancedSettings objFile, objNetDevice, wbemServices SaveVlanSettings objFile, objNetDevice, wbemServices Next objFile.WriteBlankLines(1) objFile.close Wscript.Echo "Saving done!" End Sub '**************************************************************************** Private Function SaveAdapterInfo(objFile,objAdapter,DeviceIndex) dim LastCapIndex dim index LastCapIndex=Ubound(objAdapter.Capabilities) objFile.WriteLine "Adapter Name=" & objAdapter.Caption objFile.WriteLine "Adapter Index=" & DeviceIndex objFile.WriteLine "Private Description=" objFile.Write "Adapter Capabilities=" For index = 0 to LastCapIndex-1 objFile.Write objAdapter.Capabilities(index) objFile.Write "," Next objFile.WriteLine objAdapter.Capabilities(LastCapIndex) objFile.WriteLine "Description=" & objAdapter.Description End Function '***************************************************************************** Private Function CreateConfigFile(byVal strFileName) dim fso dim file Set fso = CreateObject("Scripting.FileSystemObject") Set file=fso.CreateTextFile(strFileName,True) Set CreateConfigFile=file End Function '***************************************************************************** Private Function SaveAdvancedSettings(objFile,objAdapter,wbemServices) dim strQuery dim IANET_config dim IANet_Obj strQuery = "ASSOCIATORS OF {" & objAdapter.Path_.Path & "} WHERE ResultClass = IANet_Configuration" Set IANet_config = wbemServices.ExecQuery(strQuery) For Each IANet_Obj In IANet_config strQuery = "ASSOCIATORS OF {" & IANet_Obj.Path_.Path & "} WHERE AssocClass = IANet_SettingContext" Set IANet_config = wbemServices.ExecQuery(strQuery) Exit For Next For Each IANet_Obj In IANet_config objFile.WriteLine "setting Name=" & IANet_Obj.Caption objFile.WriteLine "setting Current Value=" & IANet_Obj.CurrentValue objFile.WriteLine "setting Description=" & IANet_Obj.Description Next End Function '***************************************************************************** Private Function SaveVlanSettings(objFile,objAdapter,wbemServices) dim strQuery dim IANet_802dot1VLANService dim IANet_802dot1VLANObj dim IANet_VLANSet dim IANet_VLANObj dim IANet_VLANconfigur dim IANet_VLANConfObj strQuery = "ASSOCIATORS OF {" & objAdapter.Path_.Path & "} WHERE ResultClass = IANet_802dot1QVLANService" Set IANet_802dot1VLANService = wbemServices.ExecQuery(strQuery) If IANet_802dot1VLANService.Count <> 0 Then For Each IANet_802dot1VLANObj In IANet_802dot1VLANService strQuery = "ASSOCIATORS OF {" & IANet_802dot1VLANObj.Path_.Path & "} WHERE ResultClass = IANet_VLAN" Set IANet_VLANSet = wbemServices.ExecQuery(strQuery) If IANet_VLANSet.Count > 0 Then For Each IANet_VLANObj In IANet_VLANSet objFile.WriteLine "VLAN Name=" & IANet_VLANObj.VLANName objFile.WriteLine "VLAN Id=" & IANet_VLANObj.VLANNumber SaveAdvancedSettings objFile,IANet_VLANObj,wbemServices Next End If Next End If End Function '***************************************************************************** Private Function SaveTeamInfo(objFile,objNetDevice,DeviceIndex,wbemServices) dim colTeamedAdapters dim TeamedAdapter dim colTeamedMemberAdapter dim TeamedMemberAdapter dim strQuery dim colTeam dim objTeam 'Access the same Team from IANet_TeamOfAdapters strQuery="ASSOCIATORS OF {" & objNetDevice.Path_.Path & "} where ResultRole=SameElement" Set colTeam = wbemServices.ExecQuery(strQuery) For Each objTeam In colTeam 'only one team in this collection objFile.WriteLine "Team Name=" & objTeam.Caption objFile.WriteLine "Description=" & objTeam.Description objFile.WriteLine "Team Settings Index=" & DeviceIndex 'Get Team Mode and Adapter count objFile.WriteLine "Team Type=" & objTeam.TeamingMode objFile.WriteLine "Adapter Count=" & objTeam.AdapterCount 'Access Members of this Team strQuery="ASSOCIATORS OF {" & objTeam.Path_.Path & "} where ResultRole=PartComponent" Set colTeamedAdapters = wbemServices.ExecQuery(strQuery) For Each TeamedAdapter In colTeamedAdapters objFile.WriteLine "Member Adapter="&TeamedAdapter.Caption 'Get Priority settings for this member adapter strQuery="REFERENCES OF {" & TeamedAdapter.Path_.Path & "} where ResultClass=IANet_TeamedMemberAdapter" Set colTeamedMemberAdapter= wbemServices.ExecQuery(strQuery) For Each TeamedMemberAdapter In colTeamedMemberAdapter objFile.WriteLine "-Preferred Priority Setting="&TeamedMemberAdapter.AdapterFunction Next Next Next End Function '===================================================================================== ' ' Sub: RestoreSettings(ByVal strFname) ' Call subs to read file to get all the info. about adapter, Team and VLANs. ' If there are the same number of adapters as settings then ' it will apply the saved settings, as long as the adapters are the same type. ' If the adapter is a different type, compatibility ' is determined by local network speed. Then applicable settings are applied. ' If number of settings and adapters are mismatched, user is prompted for selection ' '===================================================================================== Sub RestoreSettings(ByVal strFname) Dim TeamOfAdapters, TeamObj, TeamsObjSet Dim bTeam, bFound, bIsDefault, bFoundPossibleValue, bVLAN Dim arrChoices, arrExistAdapterCaps Dim strTeamName bError = FALSE 'Read File and assign found values to Teams() and Adapters() ReadFile(strFname) If bError = FALSE Then 'Create single session to make changes.. CreateSessions() 'Validate installed adapters and set bMisMatch ValidateAdapters() 'Cycle as many times as adapter sets in file, check selection and compatibility, then apply For Each AdapterObj in AdapterSets 'If StrComp(Mid(AdapterObj.Caption, 1, 4), "Team", vbTextCompare) <> 0 Then If AdapterObj.IsAteam <> TRUE Then For index = 0 to (totalAdapters - 1) strAdapterName = Adapters(index, 1, 0) strCapabilities = Adapters(index, 2, 0) strSettingsIndex = Adapters(index, 3, 0) If bMisMatch = TRUE Then CheckSelected strSettingsIndex If bUserInput = TRUE Then If bSelected = TRUE Then If strAdapterName = AdapterObj.Caption Then 'Makes changes, if settings set hasn't already been applied If Adapters(index, 0, 1) <> 1 Then ApplyAdapterSettings(strSettingsIndex) Exit For End If End If End If End If Else If strAdapterName = AdapterObj.Caption Then 'Makes changes, if settings set hasn't already been applied If Adapters(index, 0, 1) <> 1 Then ApplyAdapterSettings(strSettingsIndex) Exit For End If End If End If Next End If Next For index = 0 to (totalTeams - 1) strSettingsIndex = Teams(index, 1, 2) strTeamName = Teams(index, 0, 0) If bMisMatch = TRUE Then 'Sets bSelected CheckSelected strSettingsIndex If bSelected = TRUE Then ApplyTeamSettings(strSettingsIndex) End If Else ApplyTeamSettings(strSettingsIndex) End If Next If bModified = TRUE Then ExecApply wbemServices, strNetSerObjPath, SessionObject ElseIf bHasTeamorVLAN = TRUE Then ExecApply wbemServices, strNetSerObjPath, SessionObject ElseIf bNewTeam = TRUE Then ExecApply wbemServices, strNetSerObjPath, SessionObject End If If bNewTeam = TRUE Then WScript.Echo "New team(s) were created based on settings file" ElseIf bModified = TRUE Then WScript.Echo "New Settings were applied!" ElseIf bUserInput = TRUE Then WScript.Echo "No new settings were applied. Any existing teams were deleted." Else WScript.Echo "No new settings were applied. Any existing teams were deleted." End If ElseIf bError = TRUE Then Exit Sub End If ReleaseHandle wbemServices, strNetSerObjPath, SessionObject End Sub '===================================================================================== ' ' Sub: Sub ExecApply(ByVal wbemServices, ByVal strNetSerObjPath, ByVal SessionObject) ' '===================================================================================== Sub ExecApply(ByVal wbemServices, ByVal strNetSerObjPath, ByVal SessionObject) WScript.Echo "Executing apply..." Set NetServiceObject = wbemServices.Get(strNetSerObjPath) Set FinalTargetobj = NetServiceObject.ExecMethod_("Apply", SessionObject) End Sub '===================================================================================== ' ' Sub: Sub ReleaseHandle(ByVal wbemServices, ByVal strNetSerObjPath, ByVal SessionObject) ' '===================================================================================== Sub ReleaseHandle(ByVal wbemServices, ByVal strNetSerObjPath, ByVal SessionObject) WScript.Echo "Releasing Session Handle" Set NetServiceObject = wbemServices.Get(strNetSerObjPath) Set FinalTargetobj = NetServiceObject.ExecMethod_("ReleaseSessionHandle", SessionObject) End Sub '================================================================================================== ' ' CreateSessions() ' Create sessions to make settings changes ' '================================================================================================== Sub CreateSessions() Dim IANet_NetServiceClassDescription, cstring Set wbemServices = GetObject("winmgmts:{impersonationLevel=impersonate}//./root/IntelNcs") Set AdapterSets = wbemServices.InstancesOf("IANet_EthernetAdapter") Set SValueSet = CreateObject("WbemScripting.SWbemNamedValueSet") Set IANet_NetServiceClassDescription = wbemServices.Get("IANet_NetService") Set SessionObject = IANet_NetServiceClassDescription.Methods_.Item("Apply").InParameters.SpawnInstance_() Set NetServiceSet = wbemServices.InstancesOf("IANet_NetService") For Each NetServiceObject In NetServiceSet ' SWbemObjectSet strNetSerObjPath = NetServiceObject.Path_.Path ' Save the path for later use Set ServiceObject = NetServiceObject.ExecMethod_("GetSessionHandle") cstring = ServiceObject.SessionHandle SessionObject.SessionHandle = cstring Next SValueSet.Add "SessionHandle", cstring 'Remove any existing teams or vlans Set VLANObjSet = wbemServices.InstancesOf("IANet_VLAN",,SValueSet) For Each VLANObj In VLANObjSet bHasTeamOrVLAN = TRUE WScript.Echo "Removing any existing VLAN's..." VLANObj.Delete_ 0, SValueSet Next Set TeamsObjSet = wbemServices.InstancesOf("IANet_TeamOfAdapters",,SValueSet) For Each TeamObj In TeamsObjSet WScript.Echo "Removing any existing Teams..." bHasTeamOrVLAN = True TeamObj.Delete_ 0, SValueSet Next End Sub '====================================================================================== ' ' Sub ValidateInput(ByVal strInput) 'Validate input by removing any spaces or periods in strInput, returns strChoices '======================================================================================== Sub ValidateInput(ByVal strInput) Dim i, ii, arrChoices arrChoices = Split(strInput, ",") For i = 0 to Ubound(arrChoices) arrChoices(i) = Trim(arrChoices(i)) If Right(arrChoices(i), 1) = "." Then arrChoices(i) = Replace(arrChoices(i), ".", "") End If Next strChoices = Join(arrChoices, ",") End Sub '================================================================================================= ' ' Sub ReadFile(ByVal strFname) ' Read File and assign found values to Adapters() and Teams() arrays ' '================================================================================================= Sub ReadFile(ByVal strFname) Dim v, i, ii, x, fso, strAdapterName ,w Dim strAdapterCaps, strNewAdapterName, strAdapterIndex Dim strCapabilities, strSettingsSet, arrSettingsSets Dim strIsDefault, ts, strLine, z, numVLANS, numTVLANS Set fso = CreateObject("Scripting.FileSystemObject") If fso.FileExists (strFname) <> True Then Wscript.Echo "File can not be found or is not in the same directory as savres.vbs." WScript.Echo "Try using full pathname to config file." bError = TRUE Exit Sub Else ' Array Adapters holds all the info. about the adapter's and related VLANs info. ' Adapters( , 0, 0) is a flag of Adapter's existence ' Adapters( , 0, 1) is a flag for setting having been applied ' Adapters( , 0, 2) is Number of VLANS on Adapter ' Adapters( , 1, 0) is Adapter's Name ' Adapters( , 2, 0) is Adapter's Capabilities ' Adapters( , 3, 0) is Settings Index, for selecting settings sets ' Adapters( , 3, 1) is Settings Default, "TRUE" or "FALSE" for selecting settings sets ' Adapters( , 4, 0) is Adapter's Setting Name; Adapters( , 4, 1) is Adapter's Setting value ' ' Adapters( , x, 0) is Keyword "VLAN", any elements after this keyword are VLAN's setting name and value Redim Adapters(maxAdapterTeamVLANs, maxSettings, 5) ' Array Teams holds all the info. about the Team's and related VLANs info. ' Teams( , 0, 0) is Team's Name ' Teams( , 0, 1) is a flag for setting having been applied ' Teams( , 0, 2) is number of VLANS on Team ' Teams( , 1, 0) is Team's Type ' Teams( , 1, 1) is Team's Adapter Count ' Teams( , 1, 2) is Teams Settings Index for user selection ' Teams( , 2, 0) is keyword "MemberAdapter", ' Teams( , 2, 1) is Member adapter's caption ' Teams( , 2, 2) is Member adapter's flag for client(0) or server(1) property ' Teams( , 2, 3) is Member adapter's Preferred Priority Setting ' Teams( , 2, 4) is Member adapter's flag for "Already Added to Team" (1 or 0) ' ' Teams( , x, 0) is keyword "MemberAdapter", ' Teams( , x, 1) is related adapter's caption ' Teams( , x+1, 0) is Teams's Setting Name; Teams( , x+1, 1) is team's Setting value ' Teams( , y, 0) is Keyword "VLAN", any elements after this keyword are VLAN's setting name and value Redim Teams(maxAdapterTeamVLANs, maxSettings, 10) totalAdapters = 0 totalTeams = 0 ' Read the text file and save all the info. to two arrays - Adapters() & Teams() Set ts = fso.OpenTextFile(strFname, 1) ii = 0 v = 0 x = 0 w=0 Do Until ts.AtEndOfStream ReDim Preserve arrPrivDesc(v + 1) ReDim Preserve arrTeamPrivDesc(x + 1) strLine = ts.ReadLine() If StrComp(Mid(strLine, 1, 13), "Adapter Name=", vbTextCompare) = 0 Then numVLANS = 0 strNewAdapterName = Mid(strLine, 14) strLine = ts.ReadLine() If StrComp(Mid(strLine, 1, 14), "Adapter Index=", vbTextCompare) = 0 Then strAdapterIndex = Mid(strLine, 15) strLine = ts.ReadLine() ' strLine = ts.ReadLine()' Skip Is Default End If If StrComp(Mid(strLine, 1, 20), "Private Description=", vbTextCompare) = 0 Then arrPrivDesc(v) = Mid(strLine, 21) strLine = ts.ReadLine() v = v + 1 End If If StrComp(Mid(strLine, 1, 21), "Adapter Capabilities=", vbTextCompare) = 0 Then strCapabilities =Mid(strLine, 22) strLine = ts.ReadLine() End If ' End If strComp for Adapter Capabilities 'Assign found values to array" Adapters(totalAdapters, 1, 0) = strNewAdapterName Adapters(totalAdapters, 2, 0) = strCapabilities Adapters(totalAdapters, 3, 0) = strAdapterIndex Adapters(totalAdapters, 3, 1) = strIsDefault ts.SkipLine() 'Skip Description line 'assigning settings values" i = 4 strLine = ts.ReadLine() Do while StrComp(strLine, "", vbTextCompare) <> 0 If StrComp(Mid(strLine, 1, 13), "Setting Name=", vbTextCompare) = 0 Then Adapters(totalAdapters, i, 0) = Mid(strLine, 14) 'Setting Name strLine = ts.ReadLine() Adapters(totalAdapters, i, 1) = Mid(strLine, 23) 'Setting Value i = i + 1 strLine = ts.ReadLine() ' Skip the description ElseIf StrComp(Mid(strLine, 1, 10), "VLAN Name=", vbTextCompare) = 0 Then Do while StrComp(strLine, "", vbTextCompare) <> 0 Adapters(totalAdapters, i, 0) = "VLAN" 'Set up keyword for searching VLAN later numVLANS = numVLANS + 1 Adapters(totalAdapters, 0, 2) = numVLANS Adapters(totalAdapters, i+1, 0) = Mid(strLine, 11) 'VLAN Name strLine = ts.ReadLine() Adapters(totalAdapters, i+2, 0) = Mid(strLine, 9) 'VLAN ID i = i + 3 strLine = ts.ReadLine() Do While StrComp(Mid(strLine, 1, 10), "VLAN Name=", vbTextCompare) <> 0 If StrComp(Mid(strLine, 1, 13), "Setting Name=", vbTextCompare) = 0 Then Adapters(totalAdapters, i, 0) = Mid(strLine, 14) 'Setting Name ts.SkipLine() 'Skip Description line strLine = ts.ReadLine() Adapters(totalAdapters, i, 1) = Mid(strLine, 23) 'Setting Value End If If strLine <> "" Then strLine = ts.ReadLine() i = i + 1 Else Exit Do End If Loop Loop End If If StrComp(strLine, "", vbTextCompare) <> 0 Then strLine = ts.ReadLine() End If Loop totalAdapters = totalAdapters + 1 ElseIf StrComp(Mid(strLine, 1, 10), "Team Name=", vbTextCompare) = 0 Then Teams(totalTeams, 0, 0) = Mid(strLine, 11) strLine = ts.ReadLine() strLine = ts.ReadLine() 'Skip Description line If StrComp(Mid(strLine, 1, 20), "Team Settings Index=", vbTextCompare) = 0 Then Teams(totalTeams, 1, 2) = Mid(strLine, 21) strLine = ts.ReadLine() End If If StrComp(Mid(strLine, 1, 10), "Team Type=", vbTextCompare) = 0 Then Teams(totalTeams, 1, 0) = Mid(strLine, 11) strLine = ts.ReadLine() End If If StrComp(Mid(strLine, 1, 14), "Adapter Count=", vbTextCompare) = 0 Then Teams(totalTeams, 1, 1) = Mid(strLine, 15) strLine = ts.ReadLine() End If If StrComp(Mid(strLine, 1, 20), "Private Description=", vbTextCompare) = 0 Then arrTeamPrivDesc(x) = Mid(strLine, 21) x = x + 1 strLine = ts.ReadLine() End If i = 2 Do While StrComp(Mid(strLine, 1, 15), "Member Adapter=", vbTextCompare) = 0 Dim intTest, vi Teams(totalTeams, i, 0) = "MemberAdapter" Teams(totalTeams, i, 1) = Mid(strLine, 16) strLine = ts.Readline() If StrComp(Mid(strLine, 1, 28), "-Preferred Priority Setting=", vbTextCompare) = 0 Then Teams(totalTeams, i, 3) = Mid(strLine, 29) End If strLine = ts.ReadLine() i = i + 1 Loop Do while StrComp(strLine, "", vbTextCompare) <> 0 If StrComp(Mid(strLine, 1, 13), "Setting Name=", vbTextCompare) = 0 Then Teams(totalTeams, i, 0) = Mid(strLine, 14) 'Setting Name strLine = ts.ReadLine() Teams(totalTeams, i, 1) = Mid(strLine, 23) 'Setting Value i = i + 1 strLine = ts.ReadLine() ' Skip the description strLine = ts.ReadLine() ElseIf StrComp(Mid(strLine, 1, 10), "VLAN Name=", vbTextCompare) = 0 Then Teams(totalTeams, i, 0) = "VLAN" 'Set up keyword for searching VLAN later Teams(totalTeams, i+1, 0) = Mid(strLine, 11) 'VLAN Name strLine = ts.ReadLine() Teams(totalTeams, i+2, 0) = Mid(strLine, 9) 'VLAN ID numTVLANS = numTVLANS + 1 Teams(index, 0, 2) = numTVLANS i = i + 3 strLine = ts.ReadLine() End If Loop totalTeams = totalTeams + 1 End If Loop 'Until ts.AtEndOfStream ts.Close End If 'Debut output for values assigned to Adapters() array, uncomment parts if needed. 'WScript.Echo "VLAN settings in Adapters() array:" 'For index = 0 to (totalAdapters + totalTeams) - 1 ' For i = 4 to MaxSettings - 1 ' If Adapters(index, i, 0) = "VLAN" Then ' WScript.Echo "Adapters(" & index & ", " & i & ", 0)=" & Adapters(index, i, 0) ' WScript.Echo "Adapters(" & index & ", 0, 2)=" & Adapters(index, 0, 2) ' For ii = i to (MaxSettings - 1) ' If Adapters(index, ii, 0) <> "" Then ' WSCript.Echo "Adapters(" & index & ", " & ii & ", 0)=" & Adapters(index, ii, 0) ' If Adapters(index, ii, 1) <> "" Then ' WSCript.Echo "Adapters(" & index & ", " & ii & ", 1)=" & Adapters(index, ii, 1) ' End If ' End If ' Next ' End If ' Next ' For i = 2 to MaxSettings - 1 ' If Teams(index, i, 0) = "VLAN" Then ' WScript.Echo "Teams(" & index & ", " & i & ", 0)=" & Teams(index, i, 0) ' WScript.Echo "Teams(" & index & ", 0, 2)=" & Teams(index, 0, 2) ' For ii = i to (MaxSettings - 1) ' If Teams(index, ii, 0) <> "" Then ' WScript.Echo "Teams(" & index & ", " & ii & ", 0)=" & Teams(index, ii, 0) ' If Teams(index, ii, 1) <> "" THen ' WSCript.Echo "Teams(" & index & ", " & ii & ", 1)=" & Teams(index, ii, 1) ' End If ' End If ' Next ' End If ' Next 'Next End Sub '================================================================================================= ' ' Sub ValidateAdapters() ' Check for installed adapter count, check against settings sets and get user input for mismatches. ' Sets strInput and strChoices ' '================================================================================================= Sub ValidateAdapters() Dim ii, iii, counter Dim strTemp, strTeamTemp, strCaptions, bFound bUserInput = FALSE existTotalAdapters = 0 iii = 0 'Count existing adapters and assign captions to array for user selection For Each AdapterObj In AdapterSets ReDim Preserve Captions(iii + 1) If AdapterObj.IsAteam <> TRUE Then 'If StrComp(Mid(AdapterObj.Caption, 1, 4), "Team", vbTextCompare) <> 0 Then existTotalAdapters = existTotalAdapters + 1 Captions(iii) = AdapterObj.Caption iii = iii + 1 End If Next 'Check existing adapters against settings sets and set bFound value accordingly For index = 0 to existTotalAdapters - 1 For Each AdapterObj In AdapterSets If AdapterObj.IsAteam <> TRUE Then 'If StrComp(Mid(AdapterObj.Caption, 1, 4), "Team", vbTextCompare) <> 0 Then If StrComp(AdapterObj.Caption, Adapters(index, 1, 0)) = 0 Then bFound = True End If End If Next If bFound = TRUE Then Adapters(index, 0, 0) = TRUE Else Adapters(index, 0, 0) = FALSE End If Next 'Set string of adapter settings captions for user selection For ii = 0 to (totalAdapters - 1) If Adapters(ii, 1, 0) <> "" Then strTemp = strTemp & Adapters(ii, 3, 0) & ". " & Adapters(ii, 1, 0) & (Chr(10) & Chr(13)) & " Priv Desc: " & arrPrivDesc(ii) & (Chr(10) & Chr(13)) End If Next 'Set string of team descriptions for user selection For ii = 0 to (totalTeams - 1) If Teams(ii, 0, 0) <> "" Then strTeamTemp = strTeamTemp & Teams(ii, 1, 2) & "." & Teams(ii, 0, 0) & (Chr(10) & Chr(13)) counter = counter + 1 End If Next 'Set string of installed adapter captions for user selection For ii = 0 to Ubound(Captions) If Captions(ii) <> "" Then strCaptions = strCaptions & Captions(ii) & (Chr(10) & Chr(13)) End If Next 'Checking number of installed adapters vs. settings list, prompt user if the numbers don't match" bMisMatch = FALSE If existTotalAdapters < (totalAdapters) Then bMisMatch = TRUE strInput = InputBox("There are " & existTotalAdapters & " installed adapters and " & totalAdapters & " adapter configuration sets contained in " & strFname & "." & (Chr(10) & Chr(13)) & (Chr(10) & Chr(13)) & "Installed Adapters: " & (Chr(10) & Chr(13)) & strCaptions & (Chr(10) & Chr(13)) & "Enter selections separated by commas, no spaces or periods." & (Chr(10) & Chr(13)) & "Adapter Sets-" & (Chr(10) & Chr(13)) & strTemp & (Chr(10) & Chr(13)) & "Team Sets- " & (Chr(10) & Chr(13)) & strTeamTemp, "Mismatched Settings Sets") If strInput <> "" Then bUserInput = TRUE ValidateInput strInput Else strInput = InputBox("ERROR: No Selection Entered!" & (Chr(10) & Chr(13)) & "User-defined descriptions are listed below. Enter selections to apply, enter numbers separated by commas, no spaces or periods." & (Chr(10) & Chr(13)) & (Chr(10) & Chr(13)) & strTemp & (Chr(10) & Chr(13)) & strTeamTemp, "Enter Selection") If strInput = "" Then WScript.Echo "Script cannot continue without user selection." bUserInput = FALSE Exit Sub Else bUserInput = TRUE ValidateInput strInput End If End If ElseIf existTotalAdapters > totalAdapters Then bMisMatch = TRUE WScript.Echo "There are not enough settings sets to apply to installed adapters. Resave or check settings file." bUserInput=FALSE Exit Sub End If End Sub '================================================================================================= ' ' Sub CheckSelected(ByVal strSettingsIndex) ' Check whether current settings set was selected by any user input, defaults to true if no mismatch ' Sets bSelected to True or False ' '================================================================================================= Sub CheckSelected(ByVal strSettingsIndex) bSelected = FALSE Dim iv, v, b If strChoices <> "" Then v = InStr(1, strChoices, ",", vbTextCompare) If v > 0 Then iv = InStr(1, strChoices, strSettingsIndex, vbTextCompare) If iv > 0 Then bSelected = TRUE End If ElseIf (strChoices = strSettingsIndex) Then bSelected = TRUE End If ElseIf bMisMatch = FALSE Then bSelected = TRUE End If End Sub '================================================================================================== ' ' ApplyAdapterSettings(strSettingsIndex) ' Apply selected or all adapter settings and return status message to user ' '================================================================================================== Sub ApplyAdapterSettings(ByVal strSettingsIndex) Dim IANet_configur, IANet_Obj, IANetSettingObj Dim IANet_802dot1VLANService, IANet_802dot1VLANObj Dim IANet_VLANconfigur, IANet_VLANObj, InParameterObj, OutParameterObj Dim TempVlanObject, VlanObjectSet, IANet_VLANConfObj Dim strSettingValue, bFoundPossibleValue, VlanObject Dim strVLANName, strVLANID, bVLAN, FinalVlanObject Dim strQuery, strExistAdapterName, strExist, IANet_VLANSet Dim Dumbpath, i, ii, iii, iv, z, b, k, x, cstrPath, pos, intCurCount Dim TargetObjInstance, TargetObj, bTest, numVLANS Const wbemFlagUseAmendedQualifiers = &h20000 Set Dumbpath = CreateObject("WbemScripting.SWbemObjectPath") 'Setting applied flag to 0 Adapters(index, 0, 1) = 0 On Error Resume Next 'Updating Adapter's settings by checking if selected and if not already applied strExistAdapterName = AdapterObj.Caption If (Adapters(index, 3, 0) = strSettingsIndex) Then WScript.Echo "Applying setting set " & strSettingsIndex & " to " & AdapterObj.Caption If Adapters(index, 0, 0) Then ' Check if this adapter exists from previous validation sequence strAdapterName = Adapters(index, 1, 0) ' Get Adapter's Name from this settings set strSettingsIndex = Trim(strSettingsIndex) Set VLANObjSet = wbemServices.InstancesOf("IANet_VLAN",,SValueSet) 'If StrComp(Mid(strExistAdapterName, 1, 4), "Team", vbTextCompare) <> 0 Then If AdapterObj.IsAteam <> TRUE Then Adapters(index, 0, 1) = 1 strQuery = "ASSOCIATORS OF {" & AdapterObj.Path_.Path & "} WHERE ResultClass = IANet_Configuration" Set IANet_configur = wbemServices.ExecQuery(strQuery,,,SValueSet) For Each IANet_Obj In IANet_configur strQuery = "ASSOCIATORS OF {" & IANet_Obj.Path_.Path & "} WHERE AssocClass = IANet_SettingContext" Set IANet_configur = wbemServices.ExecQuery(strQuery,,,SValueSet) Exit For Next bVLAN = False Dim j For j = 4 to maxSettings-1 If StrComp(Adapters(index, j, 0), "", vbTextCompare) = 0 then Exit For ElseIf bVLAN Then For x = 0 to numVLANS - 1 Set TempVlanObject = wbemServices.Get("IANet_802dot1QVLANService") Set InParameterObj = TempVlanObject.Methods_.Item("CreateVLAN").InParameters.SpawnInstance_() InParameterObj.Name = Adapters(index, j, 0) InParameterObj.VLANNumber = Adapters(index, j+1, 0) strQuery = "ASSOCIATORS OF {" & AdapterObj.Path_.Path & "} WHERE ResultClass = IANet_802dot1QVLANService" Set VlanObjectSet = wbemServices.ExecQuery(strQuery,,,SValueSet) For Each VlanObject In VlanObjectSet Set FinalVlanObject = wbemServices.Get(VlanObject.Path_.Path) Set OutParameterObj = FinalVlanObject.ExecMethod_("CreateVLAN", InParameterObj, 0, SValueSet) If Err <> 0 Then ErrorCheck() End If bModified = TRUE Exit For Next WSCript.Echo "updating VLAN:" & Adapters(index, j, 0) & " settings..." For k = j+2 to maxSettings-1 If StrComp(Adapters(index, k, 0), "", vbTextCompare) = 0 then Exit For ElseIf Adapters(index, k, 0) = "VLAN" Then Exit For Else strQuery = "ASSOCIATORS OF {" & AdapterObj.Path_.Path & "}WHERE ResultClass = IANet_802dot1QVLANService" Set IANet_802dot1VLANService = wbemServices.ExecQuery(strQuery,,,SValueSet) If IANet_802dot1VLANService.Count <> 0 Then For Each IANet_802dot1VLANObj In IANet_802dot1VLANService strQuery = "ASSOCIATORS OF {" & IANet_802dot1VLANObj.Path_.Path & _ "}WHERE ResultClass = IANet_VLAN" Set IANet_VLANSet = wbemServices.ExecQuery(strQuery,,,SValueSet) For Each IANet_VLANObj In IANet_VLANSet If StrComp(IANet_VLANObj.VLANName, Adapters(index, j, 0), vbTextCompare) = 0 Then strQuery = "ASSOCIATORS OF {" & IANet_VLANObj.Path_.Path & _ "} WHERE ResultClass = IANet_Configuration" Set IANet_VLANconfigur = wbemServices.ExecQuery(strQuery,,,SValueSet) For Each IANet_VLANConfObj In IANet_VLANconfigur strQuery = "ASSOCIATORS OF {" & IANet_VLANConfObj.Path_.Path & _ "} WHERE AssocClass = IANet_SettingContext" Set IANet_VLANconfigur = wbemServices.ExecQuery(strQuery,,,SValueSet) Exit For Next For Each IANet_VLANConfObj In IANet_VLANconfigur If StrComp(IANet_VLANConfObj.Caption, Adapters(index, k, 0), vbTextCompare) = 0 Then If StrComp(IANet_VLANConfObj.CurrentValue, Adapters(index, k, 1), vbTextCompare) <> 0 Then IANet_VLANConfObj.CurrentValue = Adapters(index, k, 1) Set Dumbpath = IANet_VLANConfObj.Put_ (131073, SValueSet) bModified = True Exit For End If End If Next End If Next Next End If End If Next j = k + 1 Next bVLAN = False ElseIf StrComp(Adapters(index, j, 0), "VLAN", vbTextCompare) = 0 Then bVLAN = True numVLANS = Adapters(index, 0, 2) '"Updating Adapter's settings" ElseIf StrComp(Adapters(index, j, 0), "", vbTextCompare) <> 0 Then For Each IANet_Obj In IANet_configur If StrComp(Adapters(index, j, 0), IANet_Obj.Caption, vbTextCompare) = 0 Then If (Adapters(index, j, 0)) <> "NetworkAddress" Then If StrComp(Adapters(index, j, 1), IANet_Obj.CurrentValue, vbTextCompare) <> 0 Then Set IANetSettingObj = wbemServices.Get(IANet_Obj.Path_.Path) If StrComp(IANet_Obj.Path_.Class, "IANet_SettingEnum", vbTextCompare) = 0 Then bFoundPossibleValue = False For I = 0 To UBound(IANet_Obj.PossibleValues) If StrComp(IANet_Obj.PossibleValues(I), Adapters(index, j, 1), vbTextCompare) = 0 Then IANetSettingObj.CurrentValue = IANet_Obj.PossibleValues(I) Set Dumbpath = IANetSettingObj.Put_(wbemFlagUseAmendedQualifiers, SValueSet) bModified = True bFoundPossibleValue = True Exit For End If Next If bFoundPossibleValue = False Then WScript.Echo "Can't apply the setting '" & Adapters(index, j, 0) & "' to the new value '" & _ Adapters(index, j, 1) & "' because the new value is not a possible value." End If Else IANetSettingObj.CurrentValue = Adapters(index, j, 1) Set Dumbpath = IANetSettingObj.Put_ (wbemFlagUseAmendedQualifiers, SValueSet) bModified = True Exit For End If End If End If End If Next End If Next End If End If End If End Sub '================================================================================================= ' ' ApplyTeamSettings(ByVal strSettingsIndex) ' Apply selected settings and return status to user ' '================================================================================================= Sub ApplyTeamSettings(ByVal strSettingsIndex) Dim TargetObjInstance Dim bTeam, i, j, k, x, intCurCount, TeamAdapObj, TeamAdapObjSet, FinalVlanObject Dim IANet_configur, IANet_Obj, IANetSettingObj, TeamsObjSet, cstrPath Dim IANet_802dot1VLANService, IANet_802dot1VLANObj, TeamObjSet1, pos Dim IANet_VLANconfigur, IANet_VLANObj, Dumbpath, bTest, VLANObjectSet Dim VLANObjSet, VLANObj, b, a, TempVlanObject, InParameterObj, VlanObject Dim PartComponentString, GroupComponentString, TargetObj, TeamObj Dim TeamObj1, TeamsSet, TeamDeviceId, OutParameterObj, bFoundPossibleValue Dim strCapabilities, intTest, arrCaps, strQuery, bVLAN, numTVLANS Const wbemFlagUseAmendedQualifiers = &h20000 bModified = False On Error Resume Next If Teams(index, 1, 2) = strSettingsIndex Then bTeam = TRUE WScript.Echo "Creating Team: " & Teams(index, 0, 0) & "..." Set TeamsSet = wbemServices.Get("IANet_TeamOfAdapters",,SValueSet) Set TargetObjInstance = TeamsSet.SpawnInstance_() TargetObjInstance.TeamingMode = Teams(index, 1, 0) 'Team Mode Set Dumbpath = TargetObjInstance.Put_(131074, SValueSet) If Err <> 0 Then WScript.Echo "Team Creation Failed..." ErrorCheck() End If cstrPath = Dumbpath.Path pos = InStr(1, cstrPath, ",name=", vbTextCompare)+7 TeamDeviceId = Mid(cstrPath, pos, Len(cstrPath)-pos) Teams(index, 0, 1) = 1 'Update the team adapter's info and set adapter team compatibility" i = 2 Do While StrComp(Teams(index, i, 0), "MemberAdapter", vbTextCompare) = 0 Set TeamObjSet1 = wbemServices.InstancesOf("IANet_TeamOfAdapters",,SValueSet) Set TeamAdapObjSet = wbemServices.InstancesOf("IANet_EthernetAdapter",,SValueSet) For Each TeamObj1 In TeamObjSet1 If TeamObj1.Name = TeamDeviceId Then GroupComponentString = TeamObj1.Path_.Path Exit For End If Next For Each TeamAdapObj In TeamAdapObjSet 'If Mid(TeamAdapObj.Caption, 1, 4) <> "Team" Then If TeamAdapObj.IsAteam <> TRUE Then PartComponentString = TeamAdapObj.Path_.Path arrCaps = TeamAdapObj.Capabilities strCapabilities = Join(arrCaps) intTest = InStr(strCapabilities, 46) If intTest > 0 Then Teams(index, i, 2) = 1 Else Teams(index, i, 2) = 0 End If End If 'Check if adapter to be added to team is same type and a server adapter, 'if not, skip on this round, execute as many times as team adapter count For a = 0 to (Teams(index, 1, 1) - 1) If (Teams(index, i, 1) = TeamAdapObj.Caption) Then If Teams(index, i, 2) = 1 Then If Teams(index, i, 4) <> 1 Then Set TargetObj = wbemServices.Get("IANet_TeamedMemberAdapter",,SValueSet) Set TargetObjInstance = TargetObj.SpawnInstance_() TargetObjInstance.GroupComponent = GroupComponentString TargetObjInstance.PartComponent = PartComponentString TargetObjInstance.AdapterFunction = Teams(index, i, 3) WScript.Echo "Adding Adapter: " & TeamAdapObj.Caption Teams(index, i, 4) = 1 Set Dumbpath = TargetObjInstance.Put_(131074, SValueSet) bNewTeam = TRUE If Err <> 0 Then WScript.Echo "Adding Adapter Failed..." ErrorCheck() End If End If End If End If Next Next i = i + 1 Loop i = 2 Do While Teams(index, i, 0) = "MemberAdapter" Set TeamObjSet1 = wbemServices.InstancesOf("IANet_TeamOfAdapters",,SValueSet) Set TeamAdapObjSet = wbemServices.InstancesOf("IANet_EthernetAdapter",,SValueSet) 'Check for number of adapter supposed to be in team, then add leftovers 'Get current adapter count for a given team For Each TeamObj1 in TeamObjSet1 intCurCount = TeamObj1.AdapterCount If TeamObj1.Name = TeamDeviceId Then GroupComponentString = TeamObj1.Path_.Path Exit For End If Next For Each TeamAdapObj In TeamAdapObjSet PartComponentString = TeamAdapObj.Path_.Path For i = 2 to (Teams(index, 1, 1) + 2) 'If Mid(TeamAdapObj.Caption, 1, 4) <> "Team" Then If TeamAdapObj.IsAteam <> TRUE Then 'Check if adapter is client this time through and add if expected adapter count is less than installed count If Teams(index, 1, 1) > intCurCount Then If (Teams(index, i, 1) = TeamAdapObj.Caption) Then If Teams(index, i, 4) <> 1 Then Set TargetObj = wbemServices.Get("IANet_TeamedMemberAdapter",,SValueSet) Set TargetObjInstance = TargetObj.SpawnInstance_() TargetObjInstance.GroupComponent = GroupComponentString TargetObjInstance.PartComponent = PartComponentString TargetObjInstance.AdapterFunction = Teams(index, i, 3) WScript.Echo "Adding Adapter: " & TeamAdapObj.Caption Teams(index, i, 4) = 1 Set Dumbpath = TargetObjInstance.Put_(131074, SValueSet) bNewTeam = TRUE If Err <> 0 Then WScript.Echo "Adding Adapter Failed..." ErrorCheck() End If End If End If Else bNewTeam = TRUE End If End If Next Next Loop 'Update Team's settings if there is any change" Set TeamAdapObjSet = wbemServices.InstancesOf("IANet_EthernetAdapter",,SValueSet) For Each TeamAdapObj In TeamAdapObjSet 'If StrComp(Mid(TeamAdapObj.Caption, 1, 4), "Team", vbTextCompare) = 0 Then If AdapterObj.IsAteam = TRUE Then If StrComp(TeamDeviceId, TeamAdapObj.DeviceID, vbTextCompare) = 0 Then strQuery = "ASSOCIATORS OF {" & TeamAdapObj.Path_.Path & "} WHERE ResultClass = IANet_Configuration" Set IANet_configur = wbemServices.ExecQuery(strQuery,,,SValueSet) For Each IANet_Obj In IANet_configur strQuery = "ASSOCIATORS OF {" & IANet_Obj.Path_.Path & _ "} WHERE AssocClass = IANet_SettingContext" Set IANet_configur = wbemServices.ExecQuery(strQuery,,,SValueSet) Exit For Next bVLAN = False numTVLANS = Teams(index, 0, 2) For j = i to maxSettings-1 If StrComp(Teams(index, j, 0), "", vbTextCompare) = 0 then Exit For ElseIf bVLAN Then For x = 0 to numTVLANS - 1 WScript.Echo "Adding VLAN "& Teams(index, j, 0) &" to Team..." Set TempVlanObject = wbemServices.Get("IANet_802dot1QVLANService") Set InParameterObj = TempVlanObject.Methods_.Item("CreateVLAN").InParameters.SpawnInstance_() InParameterObj.Name = Teams(index, j, 0) InParameterObj.VLANNumber = Teams(index, j+1, 0) j = j + 3 Set VlanObjectSet = wbemServices.InstancesOf("IANet_802dot1QVLANService", , SValueSet) For Each VlanObject In VlanObjectSet If TeamDeviceId = VlanObject.Name Then Set FinalVlanObject = wbemServices.Get(VlanObject.Path_.Path) Set OutParameterObj = FinalVlanObject.ExecMethod_("CreateVLAN", InParameterObj, 0, SValueSet) Exit For End If Next Next ElseIf StrComp(Teams(index, j, 0), "VLAN", vbTextCompare) = 0 Then bVLAN = True 'numTVLANS = Teams(index, 0, 2) ElseIf StrComp(Teams(index, j, 0), "", vbTextCompare) <> 0 Then ' Updating Team's Settings For Each IANet_Obj In IANet_configur If StrComp(Teams(index, j, 0), IANet_Obj.Caption, vbTextCompare) = 0 Then If StrComp(Teams(index, j, 1), IANet_Obj.CurrentValue, vbTextCompare) <> 0 Then If StrComp(IANet_Obj.Path_.Class, "IANet_SettingEnum", vbTextCompare) = 0 Then bFoundPossibleValue = False For I = 0 To UBound(IANet_Obj.PossibleValues) If StrComp(IANet_Obj.PossibleValues(I), Teams(index, j, 1), vbTextCompare) = 0 Then IANet_Obj.CurrentValue = IANet_Obj.PossibleValues(I) Set Dumbpath = IANet_Obj.Put_(wbemFlagUseAmendedQualifiers, SValueSet) bModified = True bFoundPossibleValue = True Exit For End If Next If bFoundPossibleValue = False Then WScript.Echo "Can't apply the new '" & Teams(index, j, 0) & "' setting value of " & Teams(index, j, 1) & "' because the new value is not in the possible value range." End If Else IANet_Obj.CurrentValue = Teams(index, j, 1) Set Dumbpath = IANet_Obj.Put_ (131072, SValueSet) bModified = True Exit For End If End If End If Next End If Next End If End If Next End If End Sub '====================================================================================================== ' ' Sub ErrorCheck() ' Displays Error and Extended Error Info to standard output ' '====================================================================================================== Sub ErrorCheck() Dim errExObject, strErrText WScript.Echo "Error Number=" & Err.Number WScript.Echo "Error Description=" & Err.Description Set errExObject = CreateObject("WbemScripting.SWbemLastError") If IsNull(errExObject) = FALSE Then strErrText = errExObject.GetObjectText_ WScript.Echo "MOF=" & strErrText End If End Sub