Big in Framework 2.0 with wmi?

G

Guest

Hello,

this is my code with vs20005:

ManagementObjectSearcher searcher =
new ManagementObjectSearcher("root\\CIMV2",
"SELECT * FROM Win32_Printer");

foreach (ManagementObject queryObj in searcher.Get())
{
Console.WriteLine("-----------------------------------");
Console.WriteLine("Win32_Printer instance");
Console.WriteLine("-----------------------------------");
Console.WriteLine("Name: {0}", queryObj["Name"]);
}

I use wmi for found all printer name.
This is my exception:
Unable to find an entry point named 'GetCurrentApartmentType' in DLL
'wminet_utils.dll'.

The code work well in vs2003 but in vs2005 i have the exception.
I think there is a problem with the framework 2.0.

If you have any idea or info!

Best regards,

Wavemill
 
T

Tom Porterfield

wavemill said:
Hello,

this is my code with vs20005:

ManagementObjectSearcher searcher =
new ManagementObjectSearcher("root\\CIMV2",
"SELECT * FROM Win32_Printer");

foreach (ManagementObject queryObj in searcher.Get())
{




Console.WriteLine("-----------------------------------");
Console.WriteLine("Win32_Printer instance");
Console.WriteLine("-----------------------------------");
Console.WriteLine("Name: {0}", queryObj["Name"]); }

I use wmi for found all printer name.
This is my exception:
Unable to find an entry point named 'GetCurrentApartmentType' in DLL
'wminet_utils.dll'.

The code work well in vs2003 but in vs2005 i have the exception.
I think there is a problem with the framework 2.0.

If you have any idea or info!

Is that the complete code? It works fine here under both vs2003 and vs2005.
Are you referencing the correct version of System.Management.dll?
 
D

David Browne

wavemill said:
Hello,

this is my code with vs20005:

ManagementObjectSearcher searcher =
new ManagementObjectSearcher("root\\CIMV2",
"SELECT * FROM Win32_Printer");

foreach (ManagementObject queryObj in searcher.Get())
{

Console.WriteLine("-----------------------------------");
Console.WriteLine("Win32_Printer instance");

Console.WriteLine("-----------------------------------");
Console.WriteLine("Name: {0}", queryObj["Name"]);
}

I use wmi for found all printer name.
This is my exception:
Unable to find an entry point named 'GetCurrentApartmentType' in DLL
'wminet_utils.dll'.

The code work well in vs2003 but in vs2005 i have the exception.
I think there is a problem with the framework 2.0.


That code works fine for me in VS2005. By the way have you seen the WMI
branch on the server explorer in VS2005. You can drag the printer object
onto a component and it will create the typed object wrappers for you. Then
you can use something like

foreach (Printer ptr in Printer.GetInstances())
{
Console.WriteLine("-----------------------------------");
Console.WriteLine("Win32_Printer instance");
Console.WriteLine("-----------------------------------");
Console.WriteLine("Name: {0}", ptr.Name);
}

David
 
T

Tom Porterfield

Tom said:
Is that the complete code? It works fine here under both vs2003 and
vs2005. Are you referencing the correct version of System.Management.dll?

I know, bad form replying to myself.

You might try the following instead as it should run faster than WMI calls:

foreach (string printer in
System.Drawing.Printing.PrinterSettings.InstalledPrinters)
{
Console.WriteLine("-----------------------------------");
Console.WriteLine("Printer instance");
Console.WriteLine("-----------------------------------");
Console.WriteLine("Name: {0}", printer);
}
 
G

Guest

Hello!

Thank you for your answer!

I want use wmi not just for printer name...

I have try to open the WMI
branch on the server explorer in VS2005 but i have the same exception:
Reason: Unable to find an entry point named 'GetCurrentApartmentType' in DLL
'wminet_utils.dll'.

I don't know why!

If you have an idea!

Best regards,

Wavemill
 
W

Willy Denoyette [MVP]

| Hello,
|
| this is my code with vs20005:
|
| ManagementObjectSearcher searcher =
| new ManagementObjectSearcher("root\\CIMV2",
| "SELECT * FROM Win32_Printer");
|
| foreach (ManagementObject queryObj in searcher.Get())
| {
|
Console.WriteLine("-----------------------------------");
| Console.WriteLine("Win32_Printer instance");
|
Console.WriteLine("-----------------------------------");
| Console.WriteLine("Name: {0}", queryObj["Name"]);
| }
|
| I use wmi for found all printer name.
| This is my exception:
| Unable to find an entry point named 'GetCurrentApartmentType' in DLL
| 'wminet_utils.dll'.
|
| The code work well in vs2003 but in vs2005 i have the exception.
| I think there is a problem with the framework 2.0.
|
| If you have any idea or info!
|
| Best regards,
|
| Wavemill
|

Looks like your .NET install is broken, could you verify the version of
'wminet_utils.dll', it should be 2.0.50727.42 with size on disk 28.672
bytes? Another option is to run depends.exe or dumpbin.exe to verify whether
'GetCurrentApartmentType' is exported.

Willy.
 
G

Guest

Hello!

Thank you for your answer!

The siez and the version of wminet_utils.dll are ok.
But i have reinstall the dotnet framework and now it's ok.

Tanks for your help,

Best regards,

Wavemill
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top