⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.frm

📁 vb 快速更改网关
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form1 
   BackColor       =   &H0080C0FF&
   Caption         =   "IP网关管理器"
   ClientHeight    =   2985
   ClientLeft      =   2760
   ClientTop       =   2715
   ClientWidth     =   5565
   Icon            =   "Form1.frx":0000
   LinkTopic       =   "Form1"
   ScaleHeight     =   2985
   ScaleWidth      =   5565
   Begin VB.CommandButton Command3 
      BackColor       =   &H0080C0FF&
      Caption         =   "保存"
      Height          =   255
      Left            =   2280
      Style           =   1  'Graphical
      TabIndex        =   23
      Top             =   2520
      Width           =   855
   End
   Begin VB.TextBox Text1 
      Height          =   270
      Index           =   1
      Left            =   3840
      TabIndex        =   17
      Text            =   "1"
      Top             =   240
      Width           =   1455
   End
   Begin VB.TextBox Text2 
      Height          =   270
      Index           =   1
      Left            =   3840
      TabIndex        =   16
      Text            =   "2"
      Top             =   600
      Width           =   1455
   End
   Begin VB.TextBox Text3 
      Height          =   270
      Index           =   1
      Left            =   3840
      TabIndex        =   15
      Text            =   "3"
      Top             =   960
      Width           =   1455
   End
   Begin VB.TextBox Text4 
      Height          =   270
      Index           =   1
      Left            =   3840
      TabIndex        =   14
      Text            =   "4"
      Top             =   1680
      Width           =   1455
   End
   Begin VB.TextBox Text5 
      Height          =   270
      Index           =   1
      Left            =   3840
      TabIndex        =   13
      Text            =   "5"
      Top             =   2040
      Width           =   1455
   End
   Begin VB.Frame Frame1 
      BackColor       =   &H0080C0FF&
      Height          =   135
      Index           =   0
      Left            =   0
      TabIndex        =   12
      Top             =   1320
      Width           =   5535
   End
   Begin VB.TextBox Text5 
      Height          =   270
      Index           =   0
      Left            =   1080
      TabIndex        =   6
      Text            =   "5"
      Top             =   2040
      Width           =   1455
   End
   Begin VB.TextBox Text4 
      Height          =   270
      Index           =   0
      Left            =   1080
      TabIndex        =   5
      Text            =   "4"
      Top             =   1680
      Width           =   1455
   End
   Begin VB.TextBox Text3 
      Height          =   270
      Index           =   0
      Left            =   1080
      TabIndex        =   4
      Text            =   "3"
      Top             =   960
      Width           =   1455
   End
   Begin VB.TextBox Text2 
      Height          =   270
      Index           =   0
      Left            =   1080
      TabIndex        =   3
      Text            =   "2"
      Top             =   600
      Width           =   1455
   End
   Begin VB.TextBox Text1 
      Height          =   270
      Index           =   0
      Left            =   1080
      TabIndex        =   2
      Text            =   "1"
      Top             =   240
      Width           =   1455
   End
   Begin VB.CommandButton Command2 
      BackColor       =   &H0080C0FF&
      Caption         =   "网通"
      Height          =   255
      Left            =   3720
      Style           =   1  'Graphical
      TabIndex        =   1
      Top             =   2520
      Width           =   855
   End
   Begin VB.CommandButton Command1 
      BackColor       =   &H0080C0FF&
      Caption         =   "电信"
      Height          =   255
      Left            =   840
      Style           =   1  'Graphical
      TabIndex        =   0
      Top             =   2520
      Width           =   855
   End
   Begin VB.Label Label1 
      BackColor       =   &H0080C0FF&
      Caption         =   "IP地址:"
      Height          =   255
      Index           =   1
      Left            =   2880
      TabIndex        =   22
      Top             =   240
      Width           =   735
   End
   Begin VB.Label Label2 
      BackColor       =   &H0080C0FF&
      Caption         =   "子网掩码:"
      Height          =   255
      Index           =   1
      Left            =   2880
      TabIndex        =   21
      Top             =   600
      Width           =   855
   End
   Begin VB.Label Label3 
      BackColor       =   &H0080C0FF&
      Caption         =   "默认网关:"
      Height          =   255
      Index           =   1
      Left            =   2880
      TabIndex        =   20
      Top             =   960
      Width           =   975
   End
   Begin VB.Label Label4 
      BackColor       =   &H0080C0FF&
      Caption         =   "主DNS:"
      Height          =   255
      Index           =   1
      Left            =   2880
      TabIndex        =   19
      Top             =   1680
      Width           =   735
   End
   Begin VB.Label Label5 
      BackColor       =   &H0080C0FF&
      Caption         =   "备DNS:"
      Height          =   255
      Index           =   1
      Left            =   2880
      TabIndex        =   18
      Top             =   2040
      Width           =   735
   End
   Begin VB.Label Label5 
      BackColor       =   &H0080C0FF&
      Caption         =   "备DNS:"
      Height          =   255
      Index           =   0
      Left            =   120
      TabIndex        =   11
      Top             =   2040
      Width           =   735
   End
   Begin VB.Label Label4 
      BackColor       =   &H0080C0FF&
      Caption         =   "主DNS:"
      Height          =   255
      Index           =   0
      Left            =   120
      TabIndex        =   10
      Top             =   1680
      Width           =   735
   End
   Begin VB.Label Label3 
      BackColor       =   &H0080C0FF&
      Caption         =   "默认网关:"
      Height          =   255
      Index           =   0
      Left            =   120
      TabIndex        =   9
      Top             =   960
      Width           =   975
   End
   Begin VB.Label Label2 
      BackColor       =   &H0080C0FF&
      Caption         =   "子网掩码:"
      Height          =   255
      Index           =   0
      Left            =   120
      TabIndex        =   8
      Top             =   600
      Width           =   855
   End
   Begin VB.Label Label1 
      BackColor       =   &H0080C0FF&
      Caption         =   "IP地址:"
      Height          =   255
      Index           =   0
      Left            =   120
      TabIndex        =   7
      Top             =   240
      Width           =   735
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Declare Function GetPrivateProfileString Lib "Kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, lpKeyName As Any, ByVal lpDefault As String, ByVal lpRetunedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Private Declare Function WritePrivateProfileString Lib "Kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lplFileName As String) As Long

Private r As Long
Private entry As String
Private iniPath As String

Function GetFromINI(AppName As String, KeyName As String, FileName As String) As String
   Dim RetStr As String
   RetStr = String(255, Chr(0))
   GetFromINI = Left(RetStr, GetPrivateProfileString(AppName, ByVal KeyName, "", RetStr, Len(RetStr), FileName))
End Function

Function ChangeIP(IP As String, NM As String, GW As String, MDNS As String, SDNS As String) As String
'返回值说明:返回一个设置的中文说明.
Dim strComputer, objWMIService, colNetAdapters, strIPAddress, strSubnetMask
Dim strGateway, strGatewaymetric, strDNS, objNetAdapter, errEnable, errGateways, errDNS
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetAdapters = objWMIService.ExecQuery("Select  *  from  Win32_NetworkAdapterConfiguration  where  IPEnabled=TRUE")
strIPAddress = Array(IP)    'ip地址
strSubnetMask = Array(NM)    '子网掩码
strGateway = Array(GW)    '网关
strDNS = Array(MDNS, SDNS)     '主DNS各备DNS
strGatewaymetric = Array(1)
    
For Each objNetAdapter In colNetAdapters
       errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
       errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
       errDNS = objNetAdapter.SetDNSServerSearchOrder(strDNS)
       If errEnable = 0 And errGateways = 0 And errDNS = 0 Then
               ChangeIP = "设置成功"
       Else
               If errEnable = 0 Then
                       ChangeIP = "IP地址和子网掩码设置成功,  "
               Else
                       ChangeIP = "IP地址或子网掩码设置失败,  "
               End If
               If errGateways = 0 Then
                       ChangeIP = ChangeIP & "默认网关设置成功,  "
               Else
                       ChangeIP = ChangeIP & "默认网关设置失败,  "
               End If
               If errDNS = 0 Then
                       ChangeIP = ChangeIP & "DNS设置成功"
               Else
                       ChangeIP = ChangeIP & "DNS设置失败"
               End If
       End If
Next
  
End Function
  
  
Private Sub Command1_Click()
MsgBox ChangeIP(Text1(0).Text, Text2(0).Text, Text3(0).Text, Text4(0).Text, Text5(0).Text), vbInformation
End Sub

Private Sub Command2_Click()
MsgBox ChangeIP(Text1(1).Text, Text2(1).Text, Text3(1).Text, Text4(1).Text, Text5(1).Text), vbInformation
End Sub

Private Sub Command3_Click()
Dim i%
i = MsgBox("真的要保存“设置”吗?", vbQuestion + vbOKCancel, "保存")
If i = 1 Then
    entry$ = Text1(0).Text
    r = WritePrivateProfileString("IP1", "IP", entry, iniPath)
    If r <> 1 Then MsgBox "写序列号出错!"
    entry$ = Text2(0).Text
    r = WritePrivateProfileString("IP1", "ZW", entry, iniPath)
    If r <> 1 Then MsgBox "写序列号出错!"
    entry$ = Text3(0).Text
    r = WritePrivateProfileString("IP1", "WG", entry, iniPath)
    If r <> 1 Then MsgBox "写序列号出错!"
    entry$ = Text4(0).Text
    r = WritePrivateProfileString("IP1", "ZDNS", entry, iniPath)
    If r <> 1 Then MsgBox "写序列号出错!"
    entry$ = Text5(0).Text
    r = WritePrivateProfileString("IP1", "BDNS", entry, iniPath)
    If r <> 1 Then MsgBox "写序列号出错!"
    
    entry$ = Text1(1).Text
    r = WritePrivateProfileString("IP2", "IP", entry, iniPath)
    If r <> 1 Then MsgBox "写序列号出错!"
    entry$ = Text2(1).Text
    r = WritePrivateProfileString("IP2", "ZW", entry, iniPath)
    If r <> 1 Then MsgBox "写序列号出错!"
    entry$ = Text3(1).Text
    r = WritePrivateProfileString("IP2", "WG", entry, iniPath)
    If r <> 1 Then MsgBox "写序列号出错!"
    entry$ = Text4(1).Text
    r = WritePrivateProfileString("IP2", "ZDNS", entry, iniPath)
    If r <> 1 Then MsgBox "写序列号出错!"
    entry$ = Text5(1).Text
    r = WritePrivateProfileString("IP2", "BDNS", entry, iniPath)
    If r <> 1 Then MsgBox "写序列号出错!"
End If


End Sub

Private Sub Form_Load()
iniPath$ = App.Path + "\data.ini"
Text1(0).Text = GetFromINI("IP1", "IP", iniPath)
Text2(0).Text = GetFromINI("IP1", "ZW", iniPath)
Text3(0).Text = GetFromINI("IP1", "WG", iniPath)
Text4(0).Text = GetFromINI("IP1", "ZDNS", iniPath)
Text5(0).Text = GetFromINI("IP1", "BDNS", iniPath)

Text1(1).Text = GetFromINI("IP2", "IP", iniPath)
Text2(1).Text = GetFromINI("IP2", "ZW", iniPath)
Text3(1).Text = GetFromINI("IP2", "WG", iniPath)
Text4(1).Text = GetFromINI("IP2", "ZDNS", iniPath)
Text5(1).Text = GetFromINI("IP2", "BDNS", iniPath)

End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -