
I had also removed the filter and it still behaved the same. I am 100000000% sure that the code is perfect, just like the C# snippet has vindicated. Anyway, I run the C# application and got the message below: Unhandled Exception: System.UnauthorizedAccessException at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 e rrorCode, IntPtr errorInfo) at System.Management.ManagementObjectCollection.ManagementObjectEnumerator.Mo veNext() at WMISample.MyWMIQuery.Main() Still looks like something to do with permissions... but which user needs to have permission to what?? That's my question. My account has full permissions on wscript.exe, cscript.exe and even scrrun.dll On 29 January 2010 12:10, aki <aki275@googlemail.com> wrote:
On Fri, Jan 29, 2010 at 12:00 PM, Rad! <conradakunga@gmail.com> wrote:
Let's do some basic troubleshooting
1. Remove the filter criteria and see if it runs. If it does then the problem is the filter 2. Put back the filter but before you loop through the collection, check the number of items in the collection. there should be a Count or Length property that you can check
@Simon, while Rad has suggested the above, pls also run the general C Sharp script below. The script below runs well on my machine. HTHs to root cause, especially with the messagebox display error.
using System; using System.Management; using System.Windows.Forms; namespace WMISample { public class MyWMIQuery { public static void Main() { try { ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_ClassicCOMClassSetting"); foreach (ManagementObject queryObj in searcher.Get()) {
Console.WriteLine("-----------------------------------"); Console.WriteLine("Win32_ClassicCOMClassSetting instance");
Console.WriteLine("-----------------------------------"); Console.WriteLine("Caption: {0}", queryObj["Caption"]); } } catch (ManagementException e) { MessageBox.Show("An error occurred while querying for WMI data: " + e.Message); } } } }
Rgds.
_______________________________________________ Skunkworks mailing list Skunkworks@lists.my.co.ke http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks ------------ Skunkworks Server donations spreadsheet
http://spreadsheets.google.com/ccc?key=0AopdHkqSqKL-dHlQVTMxU1VBdU1BSWJxdy1f... ------------ Skunkworks Rules http://my.co.ke/phpbb/viewtopic.php?f=24&t=94 ------------ Other services @ http://my.co.ke Other lists ------------- Announce: http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks-announce Science: http://lists.my.co.ke/cgi-bin/mailman/listinfo/science kazi: http://lists.my.co.ke/cgi-bin/mailman/admin/kazi/general
-- Be kind to your dentist - he has fillings too...