Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone,

I'm working on a management application written in C# and using WMI.
This application allowed the user to change the computer name, autologin account, the IP address.
When I run it on Windows XP i can change the IP Adresse.
On windows 7 i always this result : 0x80041003.

Here an extract from the application :

C#
ManagementScope scope = new ManagementScope(@"\\localhost\root\cimv2");
scope.Connect();

ObjectQuery requete = new ObjectQuery("SELECT * FROM WIN32_NETWORKADAPTERCONFIGURATION");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, requete);
ManagementObjectCollection collection = searcher.Get();

if (adresse != "0.0.0.0" && adresse != string.Empty)
{
    foreach (ManagementObject element in collection)
    {
       if ((bool)element["IPENABLED"] == true)
       {
           ManagementBaseObject nouvelleadresseip = null;
           ManagementBaseObject result = null;
           ManagementBaseObject nouvellepasserrelle = null;
           ManagementBaseObject serveursDns = null;
           nouvelleadresseip = element.GetMethodParameters("ENABLESTATIC");
           nouvellepasserrelle = element.GetMethodParameters("SETGATEWAYS");
           serveursDns = element.GetMethodParameters("SETDNSSERVERSEARCHORDER");

           nouvelleadresseip["IPADDRESS"] = new string[] { adresse };
           nouvelleadresseip["SUBNETMASK"] = new string[] { masque };

           serveursDns["DNSSERVERSEARCHORDER"] = new string[]   { Properties.Resources.ServeurDnsPrefere, Properties.Resources.ServeurDnsAuxiliaire };

            result = element.InvokeMethod("ENABLESTATIC", nouvelleadresseip, null);
            resultat = Convert.ToInt64(result["RETURNVALUE"]);


On each computer I run the application with Administrator acount.

Thanks for your help
Posted
Comments
[no name] 15-Aug-12 8:28am    
And your question/problem would be what?
clemhindie 15-Aug-12 8:52am    
My problem is why i can't change the IP Address on Windows 7.
I didn't found the reason for the result 0x80041003 (Access denied).
I think i have trouble with the UAC

1 solution

That error is a WMI Access Denied error code.
http://msdn.microsoft.com/en-us/library/windows/desktop/aa394603(v=vs.85).aspx[^]
Either right click and run as Administrator or try putting in the UAC Setting "requireAdministrator"
All Admin user account run in a lesser Privilege mode until elevated.
With the Exception of the "Real Admin Account" which is disabled by default.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900