none
Need help on WMI coding errors RRS feed

  • Question

  • I'm working on to change boot order of a machine...I'm new to WMI coding

    I'm getting this wierd error ---> D:\b.vbs(22, 1) (null): 0x80041010.Line  22 here points to "For Each objSystem in ColSystem"

    To give a try, i just commented this line 9 "For Each" to see if everything  else works fine, but still it failed in the very next line...

    This time the error was wierd again which says, D:\b.vbs(23, 2) (null):  0x80041021

    Line 23 here referrred is ,

    Set objInstance =  GetObject("WinMgmts:{impersonationLevel=impersonate,AuthenticationLev el=pktprivacy}\"  & _
    strComputerName & "/" & strNameSpace & ":" &  strClassName & "=" & _
    Chr(34) & intKey & Chr(34))

    Please help me in fixing this as the errors above aren't in detail and i'm  struck with my deliverables now...

    Below is the complete code ...

    Dim strNameSpace
    Dim strComputerName
    Dim  strClassName,intKey
    strComputerName = "."
    strNameSpace =  "root/Dellomci"
    strClassName = "Dell_BootDeviceSequence"

    intKey = 0

    'Set objWMIService =  GetObject("winmgmts:{impersonationLevel=impersonate,AuthenticationLev el=pktprivacy}\"  & strComputerName & "\root\dellomci")
    'Set objWMIService =  GetObject("winmgmts:" _
    '& "{impersonationLevel=impersonate}!\\"  _
    '& strComputer & "\root\cimv2")
    'Set objWMIService =  GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" _ &  strComputer & "\root\default:StdRegProv")
    Set WshShell =  WScript.CreateObject("WScript.Shell")
    Set SWBemlocator =  CreateObject("WbemScripting.SWbemLocator")
    Set objWMIService =  SWBemlocator.ConnectServer(strComputer,"\root\CIMV2")


    Set ColSystem=objWMIService.execquery ("Select * from  Dell_BootDeviceSequence")

    For Each objSystem in ColSystem
    Set objInstance =  GetObject("WinMgmts:{impersonationLevel=impersonate,AuthenticationLev el=pktprivacy}\"  & _
    strComputerName & "/" & strNameSpace & ":" &  strClassName & "=" & _
    Chr(34) & intKey & Chr(34))

    strDeviceName =  objInstance.Properties_.Item("BootDeviceName").Value
    strDeviceOrder =  objInstance.Properties_.Item("BootOrder").Value
    strDeviceStatus =  objInstance.Properties_.Item("Status").Value
    intKey = intKey + 1

    strDeviceStatus =  objInstance.Properties_.Item("Status").Value
    strDeviceOrder =  objInstance.Properties_.Item("BootOrder").Value

    strMsg = strDeviceName
    strMsg = strMsg & vbCRLF & "Boot  Position: " & strDeviceOrder
    strMsg = strMsg & vbCRLF & "Boot  Status: "

      If strDeviceStatus = "1" Then
       strMsg = strMsg &  "On"
      Else
       strMsg = strMsg & "Off"
      End If

    If strDeviceName = "Internal HDD" Then

      strDeviceOrder = objInstance.Properties_.Item("BootOrder").Value
       strDeviceStatus = objInstance.Properties_.Item("Status").Value

      strMsg = strDeviceName
      strMsg = strMsg & vbCRLF & "Boot  Position: " & strDeviceOrder
      strMsg = strMsg & vbCRLF & "Boot  Status: "

      If strDeviceStatus = "1" Then
       strMsg = strMsg &  "On"
      Else
       strMsg = strMsg & "Off"
      End If

    End If

    If strDeviceName = "Hard-Disk Drive C:" Then

      strDeviceOrder = objInstance.Properties_.Item("BootOrder").Value
       strDeviceStatus = objInstance.Properties_.Item("Status").Value

      strMsg = strDeviceName
      strMsg = strMsg & vbCRLF & "Boot  Position: " & strDeviceOrder
      strMsg = strMsg & vbCRLF & "Boot  Status: "

      If strDeviceStatus = "1" Then
       strMsg = strMsg &  "On"
      Else
       strMsg = strMsg & "Off"
      End If

    End If

    If strDeviceName = "Onboard SATA Hard Drive" Then

      strDeviceOrder = objInstance.Properties_.Item("BootOrder").Value
       strDeviceStatus = objInstance.Properties_.Item("Status").Value
      strMsg =  strDeviceName
      strMsg = strMsg & vbCRLF & "Boot Position: " &  strDeviceOrder
      strMsg = strMsg & vbCRLF & "Boot Status: "

       If strDeviceStatus = "1" Then
       strMsg = strMsg & "On"
      Else
        strMsg = strMsg & "Off"
      End If
     
    End If

    WScript.Echo strMsg

    Next

     

    Regards,

    Bharath M

    Monday, January 3, 2011 1:01 PM

Answers