16,011,784 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View .NET questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by Member 2716158 (Top 2 by date)
Member 2716158
23-May-11 5:52am
View
Dim objMgmtClass As New ManagementClass("Win32_NetworkAdapterConfiguration")
Dim objMgmtObjCollection As ManagementObjectCollection = objMgmtClass.GetInstances()
For Each MgmtObj As ManagementObject In objMgmtObjCollection
If Not CBool(MgmtObj("IPEnabled")) Then
Continue For
End If
For Each SystemIPAddress As String In MgmtObj("IPAddress")
If SystemIPAddress.Equals(TheCurrentNicIP) Then
Try
'Add the IP alias to the configuration NIC
Dim objNewIP As ManagementBaseObject = Nothing
Dim objSetIP As ManagementBaseObject = Nothing
Dim objNewGate As ManagementBaseObject = Nothing
objNewIP = MgmtObj.GetMethodParameters("EnableStatic")
objNewGate = MgmtObj.GetMethodParameters("SetGateways")
objNewGate("DefaultIPGateway") = New String() {Gateway}
objNewGate("GatewayCostMetric") = New Integer() {1}
objNewIP("IPAddress") = New String() {TheCurrentNicIP, DeviceIPAddress}
objNewIP("SubnetMask") = New String() {TheCurrentNicSubnetMask, DeviceSubnetMask}
objSetIP = MgmtObj.InvokeMethod("EnableStatic", objNewIP, Nothing)
objSetIP = MgmtObj.InvokeMethod("SetGateways", objNewGate, Nothing)
Console.WriteLine("Updated IPAddress, SubnetMask and Gateway!")
Catch ex As Exception
Throw ex
Finally
If Not IsNothing(objMgmtClass) Then
objMgmtClass.Dispose()
objMgmtClass = Nothing
End If
If Not IsNothing(MgmtObj) Then
MgmtObj.Dispose()
MgmtObj = Nothing
End If
If Not IsNothing(objMgmtObjCollection) Then
objMgmtObjCollection.Dispose()
objMgmtObjCollection = Nothing
End If
End Try
Else
Console.WriteLine("Cannot find the adapter using the following IP Address: " & TheCurrentNicIP
End If
Next
Next
Member 2716158
18-May-11 6:02am
View
I have a windows application through which I would like to add IP Address with Subnet Mask programatically to communicate with external devices such as routers.
How to add IP Address with Subnet Mask programatically using VB.NET in Visual Studio 2010?