A problem encountered in configuring IP settings in Windows 7 using C#
I have one C# program which is used to change the TCP/IP settings in Windows. The program is built in Visual C#2010 Express Edition. It functions properly in Windows XP environment, that is, the program can change the IP address, Gateway IP and subnet
mask.
The program cannot achieve the same function in Windows 7. Actually, I have re-compiled it in Windows 7 using the same Visual C#2101 Express Edition. The newly built executive file does not return any error code as the last message "Update IP address"
is observed. However, the IP settings do not change. Is there any extra work required in Windows 7 environment? I list the whole program as below for your reference.
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
System.Management;
namespace
GetMyIP7
classProgram
{
conststring IntraLAN =
"Intel(R) PRO/100 VE Network Connection";
staticvoid Main(string[] args)
{
ManagementClass objMC =
newManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection objMOC = objMC.GetInstances();
ManagementObject ReqMO =
null;
foreach (ManagementObject objMO
in objMOC)
{
// check whether objMO's caption contains IntraLAN
if (objMO["Caption"].ToString().Contains(IntraLAN))
{
ReqMO = objMO;
break;
// return if not found
if (ReqMO == null)return;
Console.WriteLine("Found the management object with the caption containing 0", IntraLAN);
// return if not IP enabled
if (!((bool)ReqMO["ipEnabled"]))return;
Console.WriteLine("The object is IP enabled");
// get IP address if IP enabled
int n = 0;
string[] ipAddrs = (string[])ReqMO["IPAddress"];
foreach (string ip
in ipAddrs)
Console.WriteLine("IP address {0: 1", n++, ip);
// try to set IP address
try
Console.WriteLine("Try to set a new IP address");
ManagementBaseObject objNewIP =
null;
ManagementBaseObject objSetIP =
null;
ManagementBaseObject objNewGate =
null;
objNewIP = ReqMO.GetMethodParameters(
"EnableStatic");
objNewGate = ReqMO.GetMethodParameters(
"SetGateways");
string gateIP = "192.167.0.1";
string ip = "192.167.0.123";
string smask = "255.255.255.0";
objNewGate[
"DefaultIPGateway"] =
newstring[] { gateIP;
objNewGate[
"GatewayCostMetric"] =
newint[] 1;
objNewIP[
"IPAddress"] = newstring[] ip;
objNewIP[
"SubnetMask"] = newstring[] smask;
objSetIP=ReqMO.InvokeMethod(
"EnableStatic", objNewIP,
null);
objSetIP = ReqMO.InvokeMethod(
"setGateways", objNewGate,
null);
Console.WriteLine("Update IP address");
catch (Exception e)
Console.WriteLine(e.ToString());
Console.ReadLine();
Keys to the Problem A problem encountered in configuring IP settings in Windows 7 using C#
Download Error Fixer for Free Now
Hi Brian,
The issue you have posted is better suited to MSDN forums.
You may post your question in this link.
http://social.msdn.microsoft.com/Forums/en/Vsexpressvcs/threads
Hope the information helps.
Regards
Debleena S
Microsoft Answers Support Engineer
Visit our Microsoft Answers Feedback Forum and let us know what you think.
Windows Restore
- Click on the Start button on the Taskbar.
- Type "System Restore" (without quotes) in the Search box and hit Enter or,
- Click on System Restore (when you see System Restore pop up in the list of search results).
- Make sure the "Recommended restore" radio button is checked on the restore utility window.
- Click on Next and follow the instructions given.
Note: There is the option on the restore utility to select "Choose a different restore point". Unless you have a specific reason to select a different date and time than what Windows recommends, just select the recommended option stated in the steps above. If you choose to select another one, follow these steps:
Click on that desired date and time, and Windows 7 will perform a scan for any affected programs in that restore point.Once completed, click Next and follow the instructions given.
Once you have selected the restore point, your system will start the restoring process, after which you will have to restart the system.
Recommended Method to Fix the Problem: A problem encountered in configuring IP settings in Windows 7 using C#:
How to Fix A problem encountered in configuring IP settings in Windows 7 using C# with SmartPCFixer?
1. You can Download SmartPCFixer here. Install it on your system. When you open SmartPCFixer, it will perform a scan.
2. After the scan is finished, you can see the errors and problems need to be repaired. Click Fix All.
3. The Fixing part is finished, the speed of your computer will be much higher than before and the errors have been fixed.
Related: [Solved] Applications have stopped working with SP1 on Windows 7!,[Solved] I can't find auto complete text in word 2007,[Solution] I need to keep reinstalling eHome Infrared Transceiver driver everytime my computer shuts down.,How to Resolve - system restore not working windows 7?,Unable to open embedded word file on the intranet. [Solved],Solution to Error: Error: "0x81000032 make sure the C: drive is online and set to NTFS" when trying to backup to external hard drive.
,Troubleshoot:External Hard Drive not listed in Windows 7 backup wizard Error
,I'm always being signed off so annoying Tech Support
,Solution to Problem: Impossible to use Internet Explorer! I keep getting the same error message every time i try to use IE.
,Solution to Problem: Referencing data in another file
,[Anwsered] Thinkpad 8611 Boot,How to Resolve - Svchost Helper?,Fast Solution to Problem: L30 101 Driver Windows 7,Troubleshooter of Error: Io Device,How to Fix Error - Dell Laptop Code 39?
Read More: Troubleshooter of Error: Action Center - Nero not working but I haven't installed it.,[Solution] A \"Patch\" trys to attach to an \"Uninstalled\" program on every boot. How can I stop this?,Tech Support: A document I created and saved won't disappear. It reappears each time I open Word 2007,How to Fix Problem - Accessing emails on my windows laptop?,Tech Support: A Black Bar is blocking out the Menu, Favorite and Command Bars.,Cannot delete empty file icon on desktop...,Cannot download flashplayer,can't get the CIA review progrom install which is an older version,Cannot access one website-DNS server not responding.,Can't Receive or Send Vista Windows Mail - Router stopped recognizing DSL connection & wants to dial up
댓글 없음:
댓글 쓰기