By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 1,616 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

What are the required user account permissions for calling a method of a WMI class?

Joseph Martell
Expert 100+
P: 196
I am trying to make a utility program that involves changing the local computer's IP Address on Windows XP using .Net framework v3.5. I have successfully created a class that encapsulates the necessary WMI_NetworkAdapterConfiguration methods and attributes, BUT I cannot call the EnableStatic method from my non-Administrator account (I am using the InvokeMethod method of the .Net ManagementObject class)! I keep getting a return code of 91 (permission denied).

I have given my non-Administrator account the required WMI Control permissions under the Computer Management snap-in. Literally, I granted the specific non-adminstrator account all permissions from the WMI root namespace down (I specified all permissions and applied it too "this namespace and all subnamespaces" in the "adavnced" window"). I can even modify permissions for WMI control with my non-administrator account.

Despite all of this, I STILL cannot call EnableStatic without getting a return code of 91 (Access Denied). If I elevate the account to an administrator account everything works fine. This leaves me to believe that the problem is with the local security policy, not the WMI permissions. However, I cannot find a permission that would seem to be appropriate. Anyone have any ideas?

Here is some code for anyone to peruse (_moConfig is a ManagementObject pointing to the WMI_NetworkAdapterConfig object for my chosen adapter). Full classes can be provided upon request:

Expand|Select|Wrap|Line Numbers
  1.     //This is only partial code. Full classes can be supplied if required.
  2.     public class NicConfig
  3.     {
  4.         private static string _configQuery = @"SELECT * FROM Win32_NetworkAdapterConfiguration WHERE MACAddress LIKE '{0}' AND IPEnabled = 1";
  5.         public NicConfig(MACAddress mac)
  6.         {
  7.             //mac is a class that I created for the adapter's MAC address
  8.             SelectQuery query = new SelectQuery(string.Format(_configQuery, mac.ToString()));
  9.             ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
  10.  
  11.             ManagementObjectCollection configs = searcher.Get();
  12.             foreach (ManagementObject config in configs)
  13.             {
  14.                 _moConfig = config;
  15.             }
  16.         }
  17.  
  18.         public bool SetStaticIP(string IPAddress, string subnet)
  19.         {
  20.             string[] ipAddresses = { IPAddress };
  21.             string[] subnets = { subnet };
  22.             object[] parms = {ipAddresses, subnets};
  23.             object result = _moConfig.InvokeMethod("EnableStatic", parms);
  24.             uint nResult = (uint)result;
  25.  
  26.             return (nResult == 0);
  27.  
  28.         }
  29.  
  30.  
Feb 7 '13 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.