01-10-12, 11:17 PM
السلام عليكم ورحمة الله وبركاته
أخوانيأريد كود يقوم بإضافة IP في بروتوكول TCP/IPv4
حيث ان بدلا ما أدخل في محولات الأتصال واروح الخصائص وبعدين ادخل في خيارات TCP/IPv4 واضيف IP
خلاص من خلال هذا الكود أضيف IP إللي أبيه
وشكرا
''' <summary>
''' Sets the IP address of the local machine.
''' </summary>
''' <param name="IPAddress">The IP address to set the computer to</param>
''' <param name="SubnetMask">The subnet mask to set the computer to</param>
''' <param name="Gateway">The gateway to set the computer to</param>
''' <remarks>Adapted from code by Logu Krishnan at
''' http://www.codeproject.com/KB/system/cstcpipwmi.aspx
''' Requires a reference to the System.Management namespace</remarks>
Private Sub SetIP(ByVal IPAddress As String, ByVal SubnetMask As String, _
* * * * * * * * * ByVal Gateway As String)
* * Dim managementClass As New ManagementClass("Win32_NetworkAdapterConfiguration")
* * Dim mgObjCollection As ManagementObjectCollection = managementClass.GetInstances()
* * For Each mgObject As ManagementObject In mgObjCollection
* * * * If Not CType(mgObject("IPEnabled"), Boolean) Then Continue For
* * * * Try
* * * * * * Dim objNewIP As ManagementBaseObject = Nothing
* * * * * * Dim objSetIP As ManagementBaseObject = Nothing
* * * * * * Dim objNewGate As ManagementBaseObject = Nothing
* * * * * * objNewIP = mgObject.GetMethodParameters("EnableStatic")
* * * * * * objNewGate = mgObject.GetMethodParameters("SetGateways")
* * * * * * ' Set the default gateway (decided to declare and initialise
* * * * * * ' variables rather than attempting to initialize the array
* * * * * * ' while communicating with the WMI.
* * * * * * Dim tmpStrArray() As String = {Gateway}
* * * * * * objNewGate("DefaultIPGateway") = tmpStrArray
* * * * * * Dim tmpIntArray() As Integer = {1}
* * * * * * objNewGate("GatewayCostMetric") = tmpIntArray
* * * * * * ' Set the IP address and subnet.
* * * * * * tmpStrArray(0) = IPAddress
* * * * * * objNewIP("IPAddress") = tmpStrArray
* * * * * * tmpStrArray(0) = SubnetMask
* * * * * * objNewIP("SubnetMask") = tmpStrArray
* * * * * * objSetIP = mgObject.InvokeMethod("EnableStatic", objNewIP, Nothing)
* * * * * * objSetIP = mgObject.InvokeMethod("SetGateways", objNewGate, Nothing)
* * * * Catch ex As Exception
* * * * * * MessageBox.Show("An error occured: " + ex.Message)
* * * * End Try
* * Next
End Sub
' Example Usage
SetIP("192.168.1.230", "255.255.255.0", "192.168.1.51")