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_NetworkAdap terConfiguratio n methods and attributes, BUT I cannot call the EnableStatic method from my non-Administrator account (I am using the InvokeMethod method of the .Net ManagementObjec t 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 ManagementObjec t pointing to the WMI_NetworkAdap terConfig object for my chosen adapter). Full classes can be provided upon request:
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 ManagementObjec t pointing to the WMI_NetworkAdap terConfig object for my chosen adapter). Full classes can be provided upon request:
Code:
//This is only partial code. Full classes can be supplied if required.
public class NicConfig
{
private static string _configQuery = @"SELECT * FROM Win32_NetworkAdapterConfiguration WHERE MACAddress LIKE '{0}' AND IPEnabled = 1";
public NicConfig(MACAddress mac)
{
//mac is a class that I created for the adapter's MAC address
SelectQuery query = new SelectQuery(string.Format(_configQuery, mac.ToString()));
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
ManagementObjectCollection configs = searcher.Get();
foreach (ManagementObject config in configs)
{
_moConfig = config;
}
}
public bool SetStaticIP(string IPAddress, string subnet)
{
string[] ipAddresses = { IPAddress };
string[] subnets = { subnet };
object[] parms = {ipAddresses, subnets};
object result = _moConfig.InvokeMethod("EnableStatic", parms);
uint nResult = (uint)result;
return (nResult == 0);
}