Well i'm really in need of urgent help.
I've created a program (in Visual Basic Express 2012) that seeks the computer for information using WMI, like processor, graphics card, etc. Inside the IDE of Visual Basic everything goes by the book ... but the produced EXE when i try to run it a error of low memory is reported, and the programs doesn't do what's suposed to.

Can any one help ? I'm stucked on IT! Thanks in advance!

We need the exact text of the error message.
Clean and rebuild in Debug mode, see if you get the same error. I take it you get an error when running it somewhere other than your development machine, correct?

Almost certainly a permissions error, or missing|unsupported assembly

The code that i use is:

Imports System.Management

Private Function GetVideoCardName() As String

  Try
    Dim WmiSelect As New ManagementObjectSearcher _
      ("root\CIMV2", "SELECT * FROM Win32_VideoController")

    For Each WmiResults As ManagementObject In WmiSelect.Get()
       Return = WmiResults.GetPropertyValue("Name").ToString
    Next


  Catch err As ManagementException
   Return "Unable to identify the video controller!"
  End Try


End Function

i'm using Visual Basic Express 2012 and Windows 7 Ultimate

I make the reference to System.Managment. Everything is fine inside Visual Basic but
when i try to run the EXE outside Visual Basic it gives the error.

I'm not at home right now. I'll post the error as soon as i got home.
Thanks in advance for any help.

Return = WmiResults.GetPropertyValue("Name").ToString

??? That compiled?

Option Strict On
Option Explicit On
Option Infer Off

Sorry...

Return WmiResults.GetPropertyValue("Name").ToString

The problem is that i CAN GET THIS TO WORK INSIDE VISUAL BASIC but when comes to the EXE
running alone thats a NO GO!

As said above ... later on i'll post the exact ERROR CODE that i'm getting.
Thx anyway.

The Error is as following:
Unhandled exception has occurred in your application.
If you click Continue, the application will ignore this
error and attempt to continue. If you click Quit, the
application will close immediately

Insufficient memory to contiune the execution of the

See the end of this message for details on invoking 
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.OutOfMemoryException: Insufficient memory to continue the execution of the program.
   at System.Management.ThreadDispatch.Start()
   at System.Management.ManagementScope.Initialize()
   at System.Management.ManagementObjectSearcher.Initialize()
   at System.Management.ManagementObjectSearcher.Get()
   at CPU_Info.MnForm.MnForm_Load(Object sender, EventArgs e) in C:\Users\Paulo\Documents\Visual Studio 2012\Projects\CPU Info\CPU Info\MnForm.vb:line 13
   at System.EventHandler.Invoke(Object sender, EventArgs e)
   at System.Windows.Forms.Form.OnLoad(EventArgs e)
   at System.Windows.Forms.Form.OnCreateControl()
   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl()
   at System.Windows.Forms.Control.WmShowWindow(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.ContainerControl.WndProc(Message& m)
   at System.Windows.Forms.Form.WmShowWindow(Message& m)
   at System.Windows.Forms.Form.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.17929 built by: FX45RTMREL
    CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
----------------------------------------
CPU Info
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/Users/Paulo/Documents/Visual%20Studio%202012/Projects/CPU%20Info/CPU%20Info/bin/Debug/CPU%20Info.exe
----------------------------------------
Microsoft.VisualBasic
    Assembly Version: 10.0.0.0
    Win32 Version: 11.0.50709.17929 built by: FX45RTMREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/Microsoft.VisualBasic/v4.0_10.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
----------------------------------------
System
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.17929 built by: FX45RTMREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Core
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.17929 built by: FX45RTMREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
----------------------------------------
System.Windows.Forms
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.17929 built by: FX45RTMREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.17929 built by: FX45RTMREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Runtime.Remoting
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.17929 built by: FX45RTMREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Runtime.Remoting/v4.0_4.0.0.0__b77a5c561934e089/System.Runtime.Remoting.dll
----------------------------------------
System.Management
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.17929 built by: FX45RTMREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Management/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Management.dll
----------------------------------------

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
    <system.windows.forms jitDebugging="true" />
</configuration>

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.

So this crashing as soon as you start the application?

Can you post all MnForm.vb so that we can see the offending line 13?

The snippett you posted should be fine, so I can only make guesses at this point and ask that you try rebooting your machine and then run the app without VS started. There have been some report memory leak issues with WMI, but I don't see anything at this point that would trigger those.

Also what version of VS are you running and what version of the framework are you targeting? These are probably not an issue, but more info is always better.

Is this a release or debug build?

Yes it is crashing as soon as i start the exe
Man ... dont know what can i do more ... even with just the next piece of code the
same problem ...

Imports System
Imports System.Management
Imports System.Windows.Forms

Public Class MnForm

    Private Sub MnForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Try
            Dim searcher As New ManagementObjectSearcher( _
                "root\CIMV2", _
                "SELECT * FROM Win32_Processor")

            For Each queryObj As ManagementObject In searcher.Get()
                InfoBox.Items.Add("")
                InfoBox.Items.Add("      -----------------------------------")
                InfoBox.Items.Add("         CPU Information Using WMI")
                InfoBox.Items.Add("      -----------------------------------")
                InfoBox.Items.Add("")
                InfoBox.Items.Add("        " & queryObj("Name"))
                InfoBox.Items.Add("        Cores : " & queryObj("NumberofCores"))
            Next
        Catch err As ManagementException
            MessageBox.Show("An error occurred while querying for WMI data: " & err.Message)
        End Try
    End Sub
End Class

Why the hell works inside Visual Basic and not outside???

You must have added a reference in your project to System.Management as well as using the Imports statement, right?

I can compile and run that code in MnForm here no problem, in Debug or Release mode...

Yes i do the references and the import but the EXE produced keeps crashing with the
error that i've posted above?????

There is nothing apparent in your code that should be causing this problem. I'm suspecting that you may have a corrupt .Net module. Can you make try running your executable on a different machine?

One last grasp at a straw, in the IDE, go to the menu Debug->Exceptions and enable breaking on thrown for all exceptions and then see what happens.

Still the same ... I'm guessing its a problem with Windows ... Will format the PC, because i have the same OS on my laptop and the result is the same .. THE SAME PROBLEM.

Will try to install a diferent version .. and see how it goes!!!
Thx for all the help.
After installing the system will return back to the post!

This happens to you on two different machines, correct?
Both machines have the same OS?
What OS is that?
What version of the .Net Framework are you targeting?
On your project's compile properties, do you have the following set?
Option Explicit: ON, Option Strict: ON, Option Infer: Off

Now it's working ... probably a corrupt .Net Framework problem as you told before ...

Great that its working. Corrupted files are a pain, but hey can also be a warning that something may be going wonky with your harddrive. Good time to back up critical files.

It would also be great if you could close this thread by marking it solved.

Thanks

Right .. thanks ... but back to the SAME PROBLEM ... gives the same now ... i've installed NET FRAMEWORK 4.5 once again and nothing .... the same CRASHING ERROR ... I GIVE UP!

The OS is Windows 7 Ultimate, but it is a CLEAN INSTALL and after installing the OS everything was quite fine. The EXE worked fine. After installing Visual Studio Express 2012 the error comes on????
I'm all out of ideas so i guess i'll quit for now.

Ok you have a clean intall, but have you installed all the updates?
After installing VS2012 have you checked if there are updates for that as well?

Is there anything in your application that specifically requires .Net 4.5?

If not have you tried setting the Target Framework to 4.0 or even 3.5?

Yes i've tried targeting a lower net version ... still the problem shows up .. about the updates will check that out ... strange is that everything else about Visual Studio looks quite ok ... only WMI seems to be reporting ERROR!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.