473,396 Members | 1,599 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

A urgent help

Hi all,

I have used WMI method to set ipaddress in my system. But the
problem is that if i have multiple iface cards this program is setting
all the nic to same ip. I dont know how to stop this from happening. I
have my code below. Please help to identify single iface to set that
all.

public void setIP(string IPAddress, string SubnetMask, string Gateway)
{
ManagementClass objMC = new
ManagementClass("Win32_NetworkAdapterConfiguration ");
ManagementObjectCollection objMOC = objMC.GetInstances();

//objMC.GetInstances(
foreach (ManagementObject objMO in objMOC)
{
if (!(bool)objMO["IPEnabled"])
continue;

try
{
ManagementBaseObject objNewIP = null;
ManagementBaseObject objSetIP = null;
ManagementBaseObject objNewGate = null;
objNewIP =
objMO.GetMethodParameters("EnableStatic");
objNewGate =
objMO.GetMethodParameters("SetGateways");

objNewGate["DefaultIPGateway"] = new string[] {
Gateway };
objNewGate["GatewayCostMetric"] = new int[] { 1 };
objNewIP["IPAddress"] = new string[] { IPAddress };
objNewIP["SubnetMask"] = new string[] { SubnetMask
};
objSetIP = objMO.InvokeMethod("EnableStatic",
objNewIP, null);
objSetIP = objMO.InvokeMethod("SetGateways",
objNewGate, null);

//Console.WriteLine("Updated IPAddress, SubnetMask
and Default Gateway!");
}
catch (Exception ex)
{
//Console.WriteLine("Unable to Set IP : " +
ex.Message);
/*Error check*/

}

}

Its very urgent please help.

Varun

Sep 16 '06 #1
2 2102
Hello blazerguns,

You need to know the name of you network adapter and then use

SELECT * FROM Win32_NetworkAdapterConfiguration where Description = "your
network adapter name"

bHi all,
b>
bI have used WMI method to set ipaddress in my system. But
bthe problem is that if i have multiple iface cards this program is
bsetting all the nic to same ip. I dont know how to stop this from
bhappening. I have my code below. Please help to identify single iface
bto set that all.
b>
bpublic void setIP(string IPAddress, string SubnetMask, string
bGateway)
b{
bManagementClass objMC = new
bManagementClass("Win32_NetworkAdapterConfiguratio n");
bManagementObjectCollection objMOC = objMC.GetInstances();
b//objMC.GetInstances(
bforeach (ManagementObject objMO in objMOC)
b{
bif (!(bool)objMO["IPEnabled"])
bcontinue;
btry
b{
bManagementBaseObject objNewIP = null;
bManagementBaseObject objSetIP = null;
bManagementBaseObject objNewGate = null;
bobjNewIP =
bobjMO.GetMethodParameters("EnableStatic");
bobjNewGate =
bobjMO.GetMethodParameters("SetGateways");
bobjNewGate["DefaultIPGateway"] = new string[] {
bGateway };
bobjNewGate["GatewayCostMetric"] = new int[] { 1
b};
bobjNewIP["IPAddress"] = new string[] { IPAddress
b};
bobjNewIP["SubnetMask"] = new string[] {
bSubnetMask
b};
bobjSetIP = objMO.InvokeMethod("EnableStatic",
bobjNewIP, null);
bobjSetIP = objMO.InvokeMethod("SetGateways",
bobjNewGate, null);
b//Console.WriteLine("Updated IPAddress,
bSubnetMask
band Default Gateway!");
b}
bcatch (Exception ex)
b{
b//Console.WriteLine("Unable to Set IP : " +
bex.Message);
b/*Error check*/
b}
b>
b}
b>
bIts very urgent please help.
b>
bVarun
b>
---
WBR,
Michael Nemtsev :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Sep 16 '06 #2
You need to use a select query like:

select * from Win32_NetworkAdapterConfiguration where Description='adapter
description string' AND IPEnabled=true

this will return only a single adapter (provided he's IP enabled), so, there
is no need to perform this..

| if (!(bool)objMO["IPEnabled"])
| continue;
|

Willy.

"blazerguns" <bl********@gmail.comwrote in message
news:11**********************@k70g2000cwa.googlegr oups.com...
| Hi all,
|
| I have used WMI method to set ipaddress in my system. But the
| problem is that if i have multiple iface cards this program is setting
| all the nic to same ip. I dont know how to stop this from happening. I
| have my code below. Please help to identify single iface to set that
| all.
|
| public void setIP(string IPAddress, string SubnetMask, string Gateway)
| {
| ManagementClass objMC = new
| ManagementClass("Win32_NetworkAdapterConfiguration ");
| ManagementObjectCollection objMOC = objMC.GetInstances();
|
| //objMC.GetInstances(
| foreach (ManagementObject objMO in objMOC)
| {
| if (!(bool)objMO["IPEnabled"])
| continue;
|
| try
| {
| ManagementBaseObject objNewIP = null;
| ManagementBaseObject objSetIP = null;
| ManagementBaseObject objNewGate = null;
| objNewIP =
| objMO.GetMethodParameters("EnableStatic");
| objNewGate =
| objMO.GetMethodParameters("SetGateways");
|
| objNewGate["DefaultIPGateway"] = new string[] {
| Gateway };
| objNewGate["GatewayCostMetric"] = new int[] { 1 };
| objNewIP["IPAddress"] = new string[] { IPAddress };
| objNewIP["SubnetMask"] = new string[] { SubnetMask
| };
| objSetIP = objMO.InvokeMethod("EnableStatic",
| objNewIP, null);
| objSetIP = objMO.InvokeMethod("SetGateways",
| objNewGate, null);
|
| //Console.WriteLine("Updated IPAddress, SubnetMask
| and Default Gateway!");
| }
| catch (Exception ex)
| {
| //Console.WriteLine("Unable to Set IP : " +
| ex.Message);
| /*Error check*/
|
| }
|
| }
|
| Its very urgent please help.
|
| Varun
|
Sep 16 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Stefan Bauer | last post by:
Hi NG, we've got a very urgent problem... :( We are importing data with the LOAD utility. The input DATE field data is in the format DDMMYYYY (for days) and MMYYYY (for months). The target...
8
by: Mike | last post by:
Hello, I have a few rather urgent questions that I hope someone can help with (I need to figure this out prior to a meeting tomorrow.) First, a bit of background: The company I work for is...
2
by: Dimitri | last post by:
PLEASE HELP,I HAVE A DATABSE WITH MULTIPLE RECORDS AS OUTLINED BELOW EMP NO LEVEL NEXTINCREASE WAGETYPE UNIT 1000 1 0 1000 1000 1 0 1002 ...
8
by: Tim::.. | last post by:
Can someone please tell me why I keep getting the following error for some of my web application users but not others??? Even though the application runs from a central webserver??? Thanks for...
16
by: | last post by:
Hi all, I have a website running on beta 2.0 on server 2003 web sp1 and I keep getting the following error:- Error In:...
7
by: zeyais | last post by:
Here is my HTML: <style> ..leftcolumn{float:left;width:300px;border: 1px solid #ccc} ..rtcolumn{float:left;width:600px;border: 1px solid #ccc} </style> <body> <div class="leftcolumn"...
33
by: dembla | last post by:
Hey Frnds can anyone help me in this i need a program in 'c' PROGRAM to print NxN Matrix 9 1 8 1 2 3 2 7 3 as 4 5 6 6 4 5 7 8 9 in sorted form
8
by: ginnisharma1 | last post by:
Hi All, I am very new to C language and I got really big assignment in my work.I am wondering if anyone can help me.........I need to port compiler from unix to windows and compiler is written...
17
by: Saps | last post by:
Hi all. Can anyone help me here. I have loads of .sql files and i need a way to call these from my asp page so the user can run them from the browser. Meaning i have a page with a list of all...
3
by: N. Spiker | last post by:
I am attempting to receive a single TCP packet with some text ending with carriage return and line feed characters. When the text is send and the packet has the urgent flag set, the text read from...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.