Permission denied accessing WMI collection object

Hi guys, Any VBS/WMI gurus out there? I'm trying to run a script that'll return a list of all COM objects beginning with the word "datac". So my script looks as below: Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\.\root\cimv2") Set ClassCollection = objWMIService.ExecQuery("SELECT * FROM Win32_ClassicCOMClassSetting where Description like 'Datac%'") For Each item In ClassCollection WScript.Echo item.Name WScript.Echo item.Description Next I'm getting an error message at the For.. Next loop. As in the section coloured blue runs well, but when I try to iterate through the items in the ClassCollection collection, that's where I get a message saying "Microsoft VBScript runtime error: Permission denied". I know it has to do with permissions, but what object/system user needs to be granted permission to what exactly? My user account that I use has admin priviledges and I run Windows XP SP3. Thanks in advance, Me. -- Be kind to your dentist - he has fillings too...

Are you using an account that is a member of the local administrators group? On Thu, Jan 28, 2010 at 6:08 PM, Simon Mbuthia <simon.mbuthia@gmail.com>wrote:
Hi guys,
Any VBS/WMI gurus out there? I'm trying to run a script that'll return a list of all COM objects beginning with the word "datac". So my script looks as below:
Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\.\root\cimv2")
Set ClassCollection = objWMIService.ExecQuery("SELECT * FROM Win32_ClassicCOMClassSetting where Description like 'Datac%'")
For Each item In ClassCollection WScript.Echo item.Name WScript.Echo item.Description Next
I'm getting an error message at the For.. Next loop. As in the section coloured blue runs well, but when I try to iterate through the items in the ClassCollection collection, that's where I get a message saying "Microsoft VBScript runtime error: Permission denied". I know it has to do with permissions, but what object/system user needs to be granted permission to what exactly? My user account that I use has admin priviledges and I run Windows XP SP3.
Thanks in advance,
Me. -- Be kind to your dentist - he has fillings too...
_______________________________________________ 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

On Thu, Jan 28, 2010 at 6:08 PM, Simon Mbuthia <simon.mbuthia@gmail.com>wrote:
Hi guys,
Any VBS/WMI gurus out there? I'm trying to run a script that'll return a list of all COM objects beginning with the word "datac". So my script looks as below:
Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\.\root\cimv2")
Set ClassCollection = objWMIService.ExecQuery("SELECT * FROM Win32_ClassicCOMClassSetting where Description like 'Datac%'")
For Each item In ClassCollection WScript.Echo item.Name WScript.Echo item.Description Next
@Simon, thnks for the question as it helps understand WMI better. I covered WMI early last year ( with C sharp ) and I can see that the problem is with the Query string : Win32_ClassicCOMClassSetting does not have a property 'Datac%'. Class Win32_ClassicCOMClassSetting has 26 proproerties such as AppID, Control etc but not what you used. I could be wrong, pls check your select query. :-)

@RAd Yes, it is @aki, The problem is not with the syntax, but smething to do with permissions. The code is OK because scriptomatic-generated scripts [google scriptomatic] aren't generating any output. Besides, Win32_.... is a collection of objects from which I want to select the ones that begin with 'Datac'. Once I get a list of those objects, then I get attributes of each of those objects such as Name.. etc. Does that make sense? On 28 January 2010 19:57, aki <aki275@googlemail.com> wrote:
On Thu, Jan 28, 2010 at 6:08 PM, Simon Mbuthia <simon.mbuthia@gmail.com>wrote:
Hi guys,
Any VBS/WMI gurus out there? I'm trying to run a script that'll return a list of all COM objects beginning with the word "datac". So my script looks as below:
Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\.\root\cimv2")
Set ClassCollection = objWMIService.ExecQuery("SELECT * FROM Win32_ClassicCOMClassSetting where Description like 'Datac%'")
For Each item In ClassCollection WScript.Echo item.Name WScript.Echo item.Description Next
@Simon, thnks for the question as it helps understand WMI better. I covered WMI early last year ( with C sharp ) and I can see that the problem is with the Query string : Win32_ClassicCOMClassSetting does not have a property 'Datac%'. Class Win32_ClassicCOMClassSetting has 26 proproerties such as AppID, Control etc but not what you used.
I could be wrong, pls check your select query. :-)
_______________________________________________ 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...

Can you try running it in another PC? The code looks OK to me. Don't have access to a windows box currently On Fri, Jan 29, 2010 at 7:50 AM, Simon Mbuthia <simon.mbuthia@gmail.com>wrote:
@RAd Yes, it is @aki, The problem is not with the syntax, but smething to do with permissions. The code is OK because scriptomatic-generated scripts [google scriptomatic] aren't generating any output. Besides, Win32_.... is a collection of objects from which I want to select the ones that begin with 'Datac'. Once I get a list of those objects, then I get attributes of each of those objects such as Name.. etc. Does that make sense?
On 28 January 2010 19:57, aki <aki275@googlemail.com> wrote:
On Thu, Jan 28, 2010 at 6:08 PM, Simon Mbuthia <simon.mbuthia@gmail.com>wrote:
Hi guys,
Any VBS/WMI gurus out there? I'm trying to run a script that'll return a list of all COM objects beginning with the word "datac". So my script looks as below:
Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\.\root\cimv2")
Set ClassCollection = objWMIService.ExecQuery("SELECT * FROM Win32_ClassicCOMClassSetting where Description like 'Datac%'")
For Each item In ClassCollection WScript.Echo item.Name WScript.Echo item.Description Next
@Simon, thnks for the question as it helps understand WMI better. I covered WMI early last year ( with C sharp ) and I can see that the problem is with the Query string : Win32_ClassicCOMClassSetting does not have a property 'Datac%'. Class Win32_ClassicCOMClassSetting has 26 proproerties such as AppID, Control etc but not what you used.
I could be wrong, pls check your select query. :-)
_______________________________________________ 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...
_______________________________________________ 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

On Fri, Jan 29, 2010 at 7:50 AM, Simon Mbuthia <simon.mbuthia@gmail.com>wrote:
@RAd Yes, it is @aki, The problem is not with the syntax, but smething to do with permissions. The code is OK because scriptomatic-generated scripts [google scriptomatic] aren't generating any output. Besides, Win32_.... is a collection of objects from which I want to select the ones that begin with 'Datac'. Once I get a list of those objects, then I get attributes of each of those objects such as Name.. etc. Does that make sense?
@Simon, I checked sdk and still cannot find the object you are looking for. What class/object is ' datac ' under? WMI query has 494 classes. :-)

On Fri, Jan 29, 2010 at 10:12 AM, aki <aki275@googlemail.com> wrote:
On Fri, Jan 29, 2010 at 7:50 AM, Simon Mbuthia <simon.mbuthia@gmail.com>wrote:
@RAd Yes, it is @aki, The problem is not with the syntax, but smething to do with permissions. The code is OK because scriptomatic-generated scripts [google scriptomatic] aren't generating any output. Besides, Win32_.... is a collection of objects from which I want to select the ones that begin with 'Datac'. Once I get a list of those objects, then I get attributes of each of those objects such as Name.. etc. Does that make sense?
@Simon, I checked sdk and still cannot find the object you are looking for. What class/object is ' datac ' under? WMI query has 494 classes. :-)
Further to this, an example that I was working on last year : to enable auto DHCP ( execute WMI ) - Class = Win_32NetworkAdapterConfiguration ( has 41 methods and each method has parameters you can assign ) - Method = "EnableDHCP" - Instance = index of NIC cards/DUN/PPP, thus code the correct index number. usual for-each loop..... foreach(<variable> in <object>) { //statement } Result : When code script was run, it would enable DHCP. Corrections welcome...

If the error had been to do with my having used a wrong class/object, then I wouldn't be getting a permission denied error. Running it on another PC would give results because I wrote this script last year and it was working, until I reinstalled Windows on my PC. So I am sure the code is OK. In case VBS is a problem, here is the same code in JScript: ListCOM( "." ); function ListCOM( computer ) { var wmistr = "winmgmts:{impersonationLevel=impersonate}!\\\\"; wmistr += computer + "\\root\\cimv2"; var objWMIService = GetObject( wmistr ); var query = "SELECT * FROM Win32_ClassicCOMClassSetting where Cation like 'Datac%'"; var ClassCollection = objWMIService.ExecQuery( query ); var ecom = new Enumerator( ClassCollection ); for( ; !ecom.atEnd(); ecom.moveNext() ) { var icom = ecom.item(); print( "Name : " + icom.Caption ); print( "Path : " + icom.InprocServer32 + "\n" ); } } function print( msg ) { WScript.Echo( msg ); } This time, I don't get an error message, but I don't get results either. On 29 January 2010 10:27, aki <aki275@googlemail.com> wrote:
On Fri, Jan 29, 2010 at 10:12 AM, aki <aki275@googlemail.com> wrote:
On Fri, Jan 29, 2010 at 7:50 AM, Simon Mbuthia <simon.mbuthia@gmail.com>wrote:
@RAd Yes, it is @aki, The problem is not with the syntax, but smething to do with permissions. The code is OK because scriptomatic-generated scripts [google scriptomatic] aren't generating any output. Besides, Win32_.... is a collection of objects from which I want to select the ones that begin with 'Datac'. Once I get a list of those objects, then I get attributes of each of those objects such as Name.. etc. Does that make sense?
@Simon, I checked sdk and still cannot find the object you are looking for. What class/object is ' datac ' under? WMI query has 494 classes. :-)
Further to this, an example that I was working on last year : to enable auto DHCP ( execute WMI )
- Class = Win_32NetworkAdapterConfiguration ( has 41 methods and each method has parameters you can assign ) - Method = "EnableDHCP" - Instance = index of NIC cards/DUN/PPP, thus code the correct index number.
usual for-each loop.....
foreach(<variable> in <object>) { //statement }
Result : When code script was run, it would enable DHCP.
Corrections welcome...
_______________________________________________ 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...

You won't get your results because your query is wrong. Is there a property Cation? Shouldn't it be Caption? On Fri, Jan 29, 2010 at 11:20 AM, Simon Mbuthia <simon.mbuthia@gmail.com>wrote:
If the error had been to do with my having used a wrong class/object, then I wouldn't be getting a permission denied error. Running it on another PC would give results because I wrote this script last year and it was working, until I reinstalled Windows on my PC. So I am sure the code is OK.
In case VBS is a problem, here is the same code in JScript:
ListCOM( "." );
function ListCOM( computer ) { var wmistr = "winmgmts:{impersonationLevel=impersonate}!\\\\"; wmistr += computer + "\\root\\cimv2";
var objWMIService = GetObject( wmistr );
var query = "SELECT * FROM Win32_ClassicCOMClassSetting where Cation like 'Datac%'"; var ClassCollection = objWMIService.ExecQuery( query );
var ecom = new Enumerator( ClassCollection ); for( ; !ecom.atEnd(); ecom.moveNext() ) { var icom = ecom.item(); print( "Name : " + icom.Caption ); print( "Path : " + icom.InprocServer32 + "\n" ); } }
function print( msg ) { WScript.Echo( msg ); }
This time, I don't get an error message, but I don't get results either.
On 29 January 2010 10:27, aki <aki275@googlemail.com> wrote:
On Fri, Jan 29, 2010 at 10:12 AM, aki <aki275@googlemail.com> wrote:
On Fri, Jan 29, 2010 at 7:50 AM, Simon Mbuthia <simon.mbuthia@gmail.com
wrote:
@RAd Yes, it is @aki, The problem is not with the syntax, but smething to do with permissions. The code is OK because scriptomatic-generated scripts [google scriptomatic] aren't generating any output. Besides, Win32_.... is a collection of objects from which I want to select the ones that begin with 'Datac'. Once I get a list of those objects, then I get attributes of each of those objects such as Name.. etc. Does that make sense?
@Simon, I checked sdk and still cannot find the object you are looking for. What class/object is ' datac ' under? WMI query has 494 classes. :-)
Further to this, an example that I was working on last year : to enable auto DHCP ( execute WMI )
- Class = Win_32NetworkAdapterConfiguration ( has 41 methods and each method has parameters you can assign ) - Method = "EnableDHCP" - Instance = index of NIC cards/DUN/PPP, thus code the correct index number.
usual for-each loop.....
foreach(<variable> in <object>) { //statement }
Result : When code script was run, it would enable DHCP.
Corrections welcome...
_______________________________________________ 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...
_______________________________________________ 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

It's Caption, sorry, but still no results. Maybe we could focus more on the permissions issue. Any clues? On 29 January 2010 11:23, Rad! <conradakunga@gmail.com> wrote:
You won't get your results because your query is wrong. Is there a property Cation? Shouldn't it be Caption?
On Fri, Jan 29, 2010 at 11:20 AM, Simon Mbuthia <simon.mbuthia@gmail.com>wrote:
If the error had been to do with my having used a wrong class/object, then I wouldn't be getting a permission denied error. Running it on another PC would give results because I wrote this script last year and it was working, until I reinstalled Windows on my PC. So I am sure the code is OK.
In case VBS is a problem, here is the same code in JScript:
ListCOM( "." );
function ListCOM( computer ) { var wmistr = "winmgmts:{impersonationLevel=impersonate}!\\\\"; wmistr += computer + "\\root\\cimv2";
var objWMIService = GetObject( wmistr );
var query = "SELECT * FROM Win32_ClassicCOMClassSetting where Cation like 'Datac%'"; var ClassCollection = objWMIService.ExecQuery( query );
var ecom = new Enumerator( ClassCollection ); for( ; !ecom.atEnd(); ecom.moveNext() ) { var icom = ecom.item(); print( "Name : " + icom.Caption ); print( "Path : " + icom.InprocServer32 + "\n" ); } }
function print( msg ) { WScript.Echo( msg ); }
This time, I don't get an error message, but I don't get results either.
On 29 January 2010 10:27, aki <aki275@googlemail.com> wrote:
On Fri, Jan 29, 2010 at 10:12 AM, aki <aki275@googlemail.com> wrote:
On Fri, Jan 29, 2010 at 7:50 AM, Simon Mbuthia < simon.mbuthia@gmail.com> wrote:
@RAd Yes, it is @aki, The problem is not with the syntax, but smething to do with permissions. The code is OK because scriptomatic-generated scripts [google scriptomatic] aren't generating any output. Besides, Win32_.... is a collection of objects from which I want to select the ones that begin with 'Datac'. Once I get a list of those objects, then I get attributes of each of those objects such as Name.. etc. Does that make sense?
@Simon, I checked sdk and still cannot find the object you are looking for. What class/object is ' datac ' under? WMI query has 494 classes. :-)
Further to this, an example that I was working on last year : to enable auto DHCP ( execute WMI )
- Class = Win_32NetworkAdapterConfiguration ( has 41 methods and each method has parameters you can assign ) - Method = "EnableDHCP" - Instance = index of NIC cards/DUN/PPP, thus code the correct index number.
usual for-each loop.....
foreach(<variable> in <object>) { //statement }
Result : When code script was run, it would enable DHCP.
Corrections welcome...
_______________________________________________ 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...
_______________________________________________ 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
_______________________________________________ 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...

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 On Fri, Jan 29, 2010 at 11:54 AM, Simon Mbuthia <simon.mbuthia@gmail.com>wrote:
It's Caption, sorry, but still no results. Maybe we could focus more on the permissions issue. Any clues?

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.

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...

On Fri, Jan 29, 2010 at 12:20 PM, Simon Mbuthia <simon.mbuthia@gmail.com>wrote:
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<http://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
@Simon, try these and check permissions ( from run ) : Wmimgmt.msc ( and right click on properties. Click security tab and check root ) or Wbemtest.exe Your WMI log files are at : %SystemRoot%\system32\wbem\logs Beyound this, as a learner am out of ideas. poolay! :-)

I doubt the account you are using has WMI permissions. Verify using these instructions http://technet.microsoft.com/en-us/library/cc787533(WS.10).aspx On Fri, Jan 29, 2010 at 12:43 PM, aki <aki275@googlemail.com> wrote:
On Fri, Jan 29, 2010 at 12:20 PM, Simon Mbuthia <simon.mbuthia@gmail.com>wrote:
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<http://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
@Simon, try these and check permissions ( from run ) :
Wmimgmt.msc ( and right click on properties. Click security tab and check root )
or
Wbemtest.exe
Your WMI log files are at : %SystemRoot%\system32\wbem\logs
Beyound this, as a learner am out of ideas. poolay! :-)
_______________________________________________ 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

Nice info @Rad... I just found out that Administrator has no permissions on WMI Control!!! I'll look into cracking that, right after this "gastronomical" break... On 29 January 2010 12:47, Rad! <conradakunga@gmail.com> wrote:
I doubt the account you are using has WMI permissions.
Verify using these instructions http://technet.microsoft.com/en-us/library/cc787533(WS.10).aspx<http://technet.microsoft.com/en-us/library/cc787533%28WS.10%29.aspx>
On Fri, Jan 29, 2010 at 12:43 PM, aki <aki275@googlemail.com> wrote:
On Fri, Jan 29, 2010 at 12:20 PM, Simon Mbuthia <simon.mbuthia@gmail.com>wrote:
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<http://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
@Simon, try these and check permissions ( from run ) :
Wmimgmt.msc ( and right click on properties. Click security tab and check root )
or
Wbemtest.exe
Your WMI log files are at : %SystemRoot%\system32\wbem\logs
Beyound this, as a learner am out of ideas. poolay! :-)
_______________________________________________ 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
_______________________________________________ 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...

Hey guys, I have cracked the thing. I ran this command: secedit /configure /cfg C:\WINDOWS\repair\secsetup.inf /db secsetup.sdb /verbose on my DOS prompt and also ran wbemtest.exe and selected "Enable All Privileges". So the devil must have been in either of those two commands, if not both. Thanks anyway, Rad and aki. On 29 January 2010 13:48, Simon Mbuthia <simon.mbuthia@gmail.com> wrote:
Nice info @Rad... I just found out that Administrator has no permissions on WMI Control!!! I'll look into cracking that, right after this "gastronomical" break...
On 29 January 2010 12:47, Rad! <conradakunga@gmail.com> wrote:
I doubt the account you are using has WMI permissions.
Verify using these instructions http://technet.microsoft.com/en-us/library/cc787533(WS.10).aspx<http://technet.microsoft.com/en-us/library/cc787533%28WS.10%29.aspx>
On Fri, Jan 29, 2010 at 12:43 PM, aki <aki275@googlemail.com> wrote:
On Fri, Jan 29, 2010 at 12:20 PM, Simon Mbuthia <simon.mbuthia@gmail.com
wrote:
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<http://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
@Simon, try these and check permissions ( from run ) :
Wmimgmt.msc ( and right click on properties. Click security tab and check root )
or
Wbemtest.exe
Your WMI log files are at : %SystemRoot%\system32\wbem\logs
Beyound this, as a learner am out of ideas. poolay! :-)
_______________________________________________ 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
_______________________________________________ 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...
-- Be kind to your dentist - he has fillings too...

Thanks aki. I'm looking at the logs now, and I think I've found something in them. Thanks anyway. On 29 January 2010 12:43, aki <aki275@googlemail.com> wrote:
On Fri, Jan 29, 2010 at 12:20 PM, Simon Mbuthia <simon.mbuthia@gmail.com>wrote:
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<http://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
@Simon, try these and check permissions ( from run ) :
Wmimgmt.msc ( and right click on properties. Click security tab and check root )
or
Wbemtest.exe
Your WMI log files are at : %SystemRoot%\system32\wbem\logs
Beyound this, as a learner am out of ideas. poolay! :-)
_______________________________________________ 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...
participants (3)
-
aki
-
Rad!
-
Simon Mbuthia