×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Whats wrong with My Code ? error message on top

Whats wrong with My Code ? error message on top

Whats wrong with My Code ? error message on top

(OP)
System.InvalidCastException: 'Unable to cast COM object of type 'System.__ComObject' to interface type 'System.Collections.IEnumerable'.
This operation failed because the QueryInterface call on the COM component for the interface with IID '{496B0ABE-CDEE-11D3-88E8-00902754C43A}'
failed due to the following error: 'No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE))'
and the COM component does not support IDispatch::Invoke calls for DISPID_NEWENUM.'



Function GetMemory(computador, utilizador, pwd, dominio)

Dim objWMIService, objSWbemLocator
objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
objWMIService = objSWbemLocator.ConnectServer(computador, "\root\CIMv2", utilizador, pwd)
Dim objOs = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem",, 48)
For Each objOs In objWMIService
GetMemory = objOs.GetPropertyValue("FreePhysicalMemory")
Next
End Function
Public Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim struser, strpassword, strcomputer, strdomain
Dim objWMIService, objProcess, objSWbemLocator

strcomputer = "myremoteserver"
strdomain = "mydonain"
struser = "myuser"
strpassword = "mypassword"

GetMemory(strcomputer, struser, strpassword, strdomain)

objWMIService = Nothing
objProcess = Nothing
objSWbemLocator = Nothing
End Sub

Your help will be appreciated

RE: Whats wrong with My Code ? error message on top

Erm … the error message and this line

Public Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

suggest that this isn't really VBScript, but rather is VB.NET (with Option Explicit set to OFF). I presume that someone has tried to port a vbscript example into VB.NET. But fortunately the issue isn't actually a VB.NET problem (although .NET is trying to tell you the problem). Basically you are trying to enumerate an object that can't be enumerated (that's what all that stuff about DISPID_NEWENUM means).

Change

CODE

For Each objOs In objWMIService
    GetMemory = objOs.GetPropertyValue("FreePhysicalMemory")
Next 

to

CODE -->

For Each objEnum in objOS
    GetMemory = objEnum.GetPropertyValue("FreePhysicalMemory")
Next 


RE: Whats wrong with My Code ? error message on top

Did this help at all?

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close