Error in a WMI Method

G

Guest

Hi, I was implementing in a program WinForm write in C# a method that change
the DNS Sufix of networkcard of PC, well I search in the .NET documenttion
and I found a class that allow this feature, the class
"Win32_NetworkAdapterConfiguration" with the method "SetDNSSuffixSearchOrder"
that receive when argument the string array "DNSDomainSuffixSearchOrder[]"
that it would have to be the new suffix. I write in code this implemetation
but I ever receive a error when it tries to change the suffix. My code is:

using System.Management;
public static void SetaSufixo()
{
ManagementClass suffix = new
ManagementClass("Win32_NetworkAdapterConfiguration");

ManagementBaseObject newSuffix =
suffix.GetMethodParameters("SetDNSSuffixSearchOrder");

newSuffix ["DNSDomainSuffixSearchOrder"] = "any value";

suffix.InvokeMethod ("SetDNSSuffixSearchOrder", newSuffix, null);

}

Somepeople has a ideia of as I I decide this problem?

Sorry my english =(

Tks

Bruno
 
W

Willy Denoyette [MVP]

Bruno Renato said:
Hi, I was implementing in a program WinForm write in C# a method that
change
the DNS Sufix of networkcard of PC, well I search in the .NET documenttion
and I found a class that allow this feature, the class
"Win32_NetworkAdapterConfiguration" with the method
"SetDNSSuffixSearchOrder"
that receive when argument the string array "DNSDomainSuffixSearchOrder[]"
that it would have to be the new suffix. I write in code this
implemetation
but I ever receive a error when it tries to change the suffix. My code is:

using System.Management;
public static void SetaSufixo()
{
ManagementClass suffix = new
ManagementClass("Win32_NetworkAdapterConfiguration");

ManagementBaseObject newSuffix =
suffix.GetMethodParameters("SetDNSSuffixSearchOrder");

newSuffix ["DNSDomainSuffixSearchOrder"] = "any value";

suffix.InvokeMethod ("SetDNSSuffixSearchOrder", newSuffix, null);

}

Somepeople has a ideia of as I I decide this problem?

Sorry my english =(

Tks

Bruno

The "DNSDomainSuffixSearchOrder" property must be an array of strings!

Willy.
 
G

Guest

But when I implement this in the code?? I tried to use thus but also he did
not give certain:

newSuffix[1] ["DNSDomainSuffixSearchOrder"] = "any value";

or
string [] valor = new string [2];
valor[0] = "test";
newSuffix ["DNSDomainSuffixSearchOrder"] = "valor";

Which is the correct form?

Tks

Bruno Renato.
C# .NET Developer


Willy Denoyette said:
Bruno Renato said:
Hi, I was implementing in a program WinForm write in C# a method that
change
the DNS Sufix of networkcard of PC, well I search in the .NET documenttion
and I found a class that allow this feature, the class
"Win32_NetworkAdapterConfiguration" with the method
"SetDNSSuffixSearchOrder"
that receive when argument the string array "DNSDomainSuffixSearchOrder[]"
that it would have to be the new suffix. I write in code this
implemetation
but I ever receive a error when it tries to change the suffix. My code is:

using System.Management;
public static void SetaSufixo()
{
ManagementClass suffix = new
ManagementClass("Win32_NetworkAdapterConfiguration");

ManagementBaseObject newSuffix =
suffix.GetMethodParameters("SetDNSSuffixSearchOrder");

newSuffix ["DNSDomainSuffixSearchOrder"] = "any value";

suffix.InvokeMethod ("SetDNSSuffixSearchOrder", newSuffix, null);

}

Somepeople has a ideia of as I I decide this problem?

Sorry my english =(

Tks

Bruno

The "DNSDomainSuffixSearchOrder" property must be an array of strings!

Willy.
 
W

Willy Denoyette [MVP]

Bruno Renato said:
But when I implement this in the code?? I tried to use thus but also he
did
not give certain:

newSuffix[1] ["DNSDomainSuffixSearchOrder"] = "any value";

or
string [] valor = new string [2];
valor[0] = "test";
newSuffix ["DNSDomainSuffixSearchOrder"] = "valor";

Which is the correct form?

Tks

Bruno Renato.
C# .NET Developer

Make it...
string [] valor = new string [1];
valor[0] = "test";
newSuffix ["DNSDomainSuffixSearchOrder"] = valor;
or:
newSuffix ["DNSDomainSuffixSearchOrder"] = new string [1] {"Test"};

Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top