Joao Marques
Programmer
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
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