当前位置: 源码素材网 » VB教程 » 详情页

VB6.0 远程终端开启工具VB代码分享

  •   时间:2019-07-11
  • 概述:远程终端

远程终端开启工具VB代码分享,远程终端开启器,对注册表进行操作的远程控制工具代码,每个都涉及到远程终端的注册表键值。

VERSION 5.00
Begin VB.Form Form1
   Caption         =   "远程终端开启器 "
   ClientHeight    =   5790
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   4245
   Icon            =   "Form1.frx":0000
   LinkTopic       =   "Form1"
   ScaleHeight     =   5790
   ScaleWidth      =   4245
   StartUpPosition =   3  '窗口缺省
   Begin VB.Frame Frame2
      Caption         =   "启动信息"
      Height          =   855
      Left            =   240
      TabIndex        =   10
      Top             =   3120
      Width           =   3375
      Begin VB.OptionButton Option1
         Caption         =   "Option1"
         Height          =   255
         Left            =   2280
         TabIndex        =   12
         Top             =   360
         Width           =   255
      End
      Begin VB.Label Label4
         Caption         =   "是否重新启动: "
         Height          =   255
         Left            =   600
         TabIndex        =   11
         Top             =   360
         Width           =   1335
      End
   End
   Begin VB.PictureBox Picture1
      BackColor       =   &H00FFFFFF&
      FillColor       =   &H00FFFFFF&
      ForeColor       =   &H00FFFFFF&
      Height          =   855
      Left            =   120
      ScaleHeight     =   795
      ScaleWidth      =   3555
      TabIndex        =   9
      Top             =   4800
      Width           =   3615
      Begin VB.PictureBox Picture2
         BackColor       =   &H00FFFFFF&
         BorderStyle     =   0  'None
         Height          =   375
         Left            =   720
         Picture         =   "Form1.frx":030A
         ScaleHeight     =   375
         ScaleWidth      =   375
         TabIndex        =   15
         Top             =   480
         Width           =   375
      End
      Begin VB.Label Label6
         BackColor       =   &H00FFFFFF&
         Caption         =   "<开源爱好者>杂志"
         BeginProperty Font
            Name            =   "宋体"
            Size            =   10.5
            Charset         =   134
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   1200
         TabIndex        =   14
         Top             =   480
         Width           =   2295
      End
      Begin VB.Line Line3
         X1              =   600
         X2              =   2760
         Y1              =   360
         Y2              =   360
      End
      Begin VB.Label Label5
         BackColor       =   &H00FFFFFF&
         Caption         =   "远程终端开启器"
         BeginProperty Font
            Name            =   "宋体"
            Size            =   9
            Charset         =   134
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00000000&
         Height          =   255
         Left            =   120
         TabIndex        =   13
         Top             =   120
         Width           =   3255
      End
   End
   Begin VB.CommandButton end
      Caption         =   "关闭"
      Height          =   375
      Left            =   2280
      TabIndex        =   8
      Top             =   4080
      Width           =   855
   End
   Begin VB.CommandButton begin
      Caption         =   "开启"
      Height          =   375
      Left            =   720
      TabIndex        =   7
      Top             =   4080
      Width           =   855
   End
   Begin VB.Frame Frame1
      Caption         =   "连接信息"
      Height          =   1935
      Left            =   240
      TabIndex        =   2
      Top             =   1080
      Width           =   3375
      Begin VB.TextBox password
         Height          =   270
         Left            =   1440
         TabIndex        =   6
         Top             =   1200
         Width           =   1335
      End
      Begin VB.TextBox username
         Height          =   270
         Left            =   1440
         TabIndex        =   4
         Text            =   "administrator"
         Top             =   480
         Width           =   1335
      End
      Begin VB.Label Label3
         Caption         =   "密码"
         Height          =   255
         Left            =   360
         TabIndex        =   5
         Top             =   1200
         Width           =   1095
      End
      Begin VB.Label Label2
         Caption         =   "用户名"
         Height          =   255
         Left            =   360
         TabIndex        =   3
         Top             =   480
         Width           =   1095
      End
   End
   Begin VB.TextBox ip
      Height          =   270
      Left            =   1920
      TabIndex        =   1
      Text            =   "127.0.0.1"
      Top             =   480
      Width           =   1575
   End
   Begin VB.Line Line2
      BorderColor     =   &H00808080&
      BorderWidth     =   3
      X1              =   0
      X2              =   3960
      Y1              =   4560
      Y2              =   4560
   End
   Begin VB.Label Label1
      Caption         =   "远程目标IP地址"
      Height          =   375
      Left            =   360
      TabIndex        =   0
      Top             =   480
      Width           =   2055
   End
   Begin VB.Line Line1
      BorderColor     =   &H00808080&
      BorderWidth     =   3
      X1              =   0
      X2              =   6360
      Y1              =   120
      Y2              =   120
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'download by http://www.srcfans.com
Private Sub begin_Click()
'这个是开始按纽
'首先判断是不是IP地址
If Len(ip.Text) < 7 Then Exit Sub  '如果取出IP的长度是小于7位,那么将退出,以最低的IP:1.1.1.1,刚好7位。
Dim a As Byte
Dim iptest As String
ipok = Split(ip.Text, ".", 4)
'利用Split函数来判断IP正确,Split的用法:传回数组 = Split(原始字串, 要找的字串, 拆成几个数组) 。例如:Private Sub Command1_Click()
'Dim MyStr As String
'MyStr = "1234567123456712345"
'MyStrs = Split(MyStr, "67", 2)
'For Each Strs In MyStrs
'Print Strs
'Next
'End Sub
'●输出结果:"12345"、"123456712345" ,这里将IP地址分为利用.为查找字符来分成4段数字进行判断是否正确。
For a = 0 To 3
If (Not IsNumeric(ipok(a))) Then  'IsNumeric函数的描述:返回 Boolean 值指明表达式的值是否为数字,这里依次判断四段是不是数字。如果不是的话,则执行下面的msgbox语句。
MsgBox "请输入正确的IP地址", vbCritical
Exit Sub
End If
Next
For a = 0 To 3
If CInt(ipok(a)) > 255 Or CInt(ipok(a)) < 0 Then
MsgBox "请输入正确的IP地址", vbCritical
Exit Sub
End If
Next
  ' ●CInt。
  '小数转整数,采四舍五入的方式计算。
'Ex:
  '     MyVal = CInt(HerVal)
   '    MyVal = CInt(Val(Text1.Text))
    '   MyVal = CInt(123.45)
     '  MyVal = CInt(-12345)
      ' Debug.Print CInt(-123.45)
       'CInt(12345) 传回 12345
       'CInt(12345.4) 传回 12345
       'CInt(12345.5) 传回 12346
       'CInt(-12345.4) 传回 -12345
       'CInt(-12345.5) 传回 -12346
'这里用来判断4段字符是不是大于0和小于255的数字?
For a = 0 To 3
iptest = iptest + ipok(a)
Next
iptest = Trim(iptest)
username.Text = Trim(username.Text)  'trim函数去掉字符的左右空格。
password.Text = Trim(password.Text)
'以下部分是利用WMI组件实现远程连接,修改注册表,重新启动操作
Set objlocator = CreateObject("wbemscripting.swbemlocator") '建立WMI对象
Set objswbemservices = objlocator.connectserver(ipp, "root/cimv2", username.Text, password.Text) '利用connectserver与远程主机进行连接
objswbemservices.security_.privileges.Add 23, True
objswbemservices.security_.privileges.Add 18, True
Set colinstoscaption = objswbemservices.execquery("select caption from win32_operatingsystem")
For Each objinstoscaption In colinstoscaption
   If InStr(objinstoscaption.Caption, "Server") > 0 Then
      MsgBox "成功建立连接", vbInformation
   Else
      MsgBox "目标主机系统:" & objinstoscaption.Caption
      Dim re As VbMsgBoxResult
      re = MsgBox("进行远程终端服务的开启[y/n]", vbOKCancel)
      If re = vbCancel Then Exit Sub
      End If
Next
Set objinstreg = objlocator.connectserver(ipaddress, "root/default", username, password).get("stdregprov")
HKLM = &H80000002
With objinstreg
.createkey , "SOFTWARE\Microsoft\Windows\CurrentVersion\netcache"
.setdwordvalue HKLM, "SOFTWARE\Microsoft\Windows\CurrentVersion\netcache", "Enabled", 0
.createkey HKLM, "SOFTWARE\Policies\Microsoft\Windows\Installer"
.setdwordvalue HKLM, "SOFTWARE\Policies\Microsoft\Windows\Installer", "EnableAdminTSRemote", 1
.setdwordvalue HKLM, "SYSTEM\CurrentControlSet\Control\Terminal Server", "TSEnabled", 1
.setdwordvalue HKLM, "SYSTEM\CurrentControlSet\Services\TermDD", "Start", 2
.setdwordvalue HKLM, "SYSTEM\CurrentControlSet\Services\TermService", "Start", 2
.setstringvalue HKLM, ".DEFAULT\Keyboard Layout\Toggle", "Hotkey", "1"
.setdwordvalue HKLM, "SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp", "PortNumber", "3389"
End With
'设置每个涉及远程终端的注册表键的值
flag = 0
If Option1.Value = True Then
rebt = "/fr"
End If
If rebt = "/fr" Then flag = 6
If flag <> 0 Then
   MsgBox "请等待……"
   strwqlquery = "select * from win32_operatingsystem where primary='true'"
   Set colinstances = objswbemservices.execquery(strwqlquery)
   For Each objinstance In colinstances
      objinstance.win32shutdown (flag)
   Next
   Else
   MsgBox "等待远程主机重新启动"
End If
End Sub
Private Sub end_Click()
End
End Sub

    相关声明:

      若“VB6.0 远程终端开启工具VB代码分享”有损您的权益,请告之我们删除内容。
      部分文章来源于网络,版权归原作者所有。