?? form1.frm
字號:
VERSION 5.00
Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX"
Object = "{3B7C8863-D78F-101B-B9B5-04021C009402}#1.1#0"; "RICHTX32.OCX"
Object = "{6B7E6392-850A-101B-AFC0-4210102A8DA7}#1.1#0"; "COMCTL32.OCX"
Begin VB.Form frmMain
Caption = "在 WINDOWS 應(yīng)用程序中遠(yuǎn)程執(zhí)行 Unix 命令"
ClientHeight = 7290
ClientLeft = 1575
ClientTop = 795
ClientWidth = 9345
LinkTopic = "Form1"
MaxButton = 0 'False
ScaleHeight = 486
ScaleMode = 3 'Pixel
ScaleWidth = 623
Begin ComctlLib.StatusBar stb
Align = 2 'Align Bottom
Height = 375
Left = 0
TabIndex = 5
Top = 6915
Width = 9345
_ExtentX = 16484
_ExtentY = 661
SimpleText = ""
_Version = 327680
BeginProperty Panels {0713E89E-850A-101B-AFC0-4210102A8DA7}
NumPanels = 2
BeginProperty Panel1 {0713E89F-850A-101B-AFC0-4210102A8DA7}
Object.Width = 5292
MinWidth = 5292
TextSave = ""
Key = "state"
Object.Tag = ""
EndProperty
BeginProperty Panel2 {0713E89F-850A-101B-AFC0-4210102A8DA7}
Alignment = 2
Object.Width = 11377
MinWidth = 11377
Text = "請輸入執(zhí)行后能返回命令提示符的Unix命令,因?yàn)樯戏絻H是命令結(jié)果回顯!"
TextSave = "請輸入執(zhí)行后能返回命令提示符的Unix命令,因?yàn)樯戏絻H是命令結(jié)果回顯!"
Key = "tip"
Object.Tag = ""
EndProperty
EndProperty
MouseIcon = "Form1.frx":0000
End
Begin VB.Frame Frame1
Caption = " Unix命令執(zhí)行結(jié)果回顯 (請?jiān)谙路矫钶斎肟蛑休斎腩愃苐s、pwd等執(zhí)行完畢后能返回命令提示符的Unix命令) "
ForeColor = &H00FF0000&
Height = 6255
Left = 120
TabIndex = 3
Top = 0
Width = 9135
Begin RichTextLib.RichTextBox rtb
Height = 5895
Left = 120
TabIndex = 4
Top = 240
Width = 8895
_ExtentX = 15690
_ExtentY = 10398
_Version = 327680
BackColor = -2147483641
ReadOnly = -1 'True
ScrollBars = 3
TextRTF = $"Form1.frx":001C
End
End
Begin VB.Timer Timer1
Interval = 1000
Left = 6240
Top = 6480
End
Begin VB.TextBox Text1
BeginProperty Font
Name = "宋體"
Size = 9
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00FF0000&
Height = 270
Left = 2160
TabIndex = 1
Text = "Text1"
Top = 6480
Width = 3735
End
Begin MSWinsockLib.Winsock sck
Left = 8760
Top = 6480
_ExtentX = 741
_ExtentY = 741
End
Begin VB.CommandButton Command1
Caption = "遠(yuǎn)程執(zhí)行Unix命令"
Height = 375
Left = 6720
TabIndex = 0
Top = 6420
Width = 2175
End
Begin VB.Label Label1
Caption = "輸入要執(zhí)行的Unix命令"
ForeColor = &H00FF0000&
Height = 255
Left = 240
TabIndex = 2
Top = 6480
Width = 1815
End
Begin VB.Menu mnuFile
Caption = "文件(&F)"
Begin VB.Menu mnuFileConnect
Caption = "連接(&C)"
End
Begin VB.Menu b
Caption = "-"
End
Begin VB.Menu mnuFileSet
Caption = "設(shè)置(&S)"
End
Begin VB.Menu as
Caption = "-"
End
Begin VB.Menu mnuFileExit
Caption = "退出(&X)"
End
End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim blnLoginSuccess As Boolean '登錄是否成功標(biāo)志
Dim intConnectTime As Integer '登錄時(shí)間
'============================
' 遠(yuǎn)程執(zhí)行Unix命令
Private Sub Command1_Click()
Dim strUnixCommand As String
strUnixCommand = Trim(Text1.Text)
If LCase(strUnixCommand) = "vi" Then
MsgBox "請輸入執(zhí)行完畢后能返回命令提示符的Unix命令,比如ls、pwd...等等!", 48
Text1.Text = ""
Text1.SetFocus
Exit Sub
End If
If Not RemoteExeUnixCommand(sck, strUnixCommand) Or StrComp(UCase(strUnixCommand), "EXIT", vbTextCompare) = 0 Then
blnLoginSuccess = False
Command1.Enabled = False
mnuFileConnect.Enabled = True
rtb.Text = ""
If sck.State <> sckClosed Then sck.Close
DoEvents
stb.Panels("state").Text = ""
Else
stb.Panels("state").Text = "命令 " + Trim(Text1.Text) + " 執(zhí)行完畢!"
End If
Text1.Text = ""
End Sub
'=========| 載入窗體 |========
Private Sub Form_Load()
rtb.Text = ""
Text1.Text = ""
blnLoginSuccess = False
Command1.Enabled = False
If Not GetUnixInfo Then
MsgBox "你還沒有設(shè)置UNIX主機(jī)的IP地址、登錄用戶名及密碼!" + vbCrLf + _
"請先在“文件”菜單中進(jìn)行設(shè)置!", 48
Call InitUnixInfo
mnuFileConnect.Enabled = False
End If
Timer1.Enabled = False
intConnectTime = 0
stb.Panels("state").Text = ""
End Sub
'=========| 菜單--連接 |=========
Private Sub mnuFileConnect_Click()
Timer1.Enabled = True
intConnectTime = 0
blnLoginSuccess = False
Command1.Enabled = False
'-------------
If sck.State <> sckClosed Then sck.Close
DoEvents
InitTelnetWinSock sck, strIP
On Error GoTo ERR
sck.Connect
Me.MousePointer = 11
stb.Panels("state").Text = "正在與 " + strIP + " 連接..."
Do
DoEvents
Loop Until sck.State = sckConnected Or intConnectTime > 6
If sck.State <> sckConnected Then
MsgBox "與UNIX主機(jī)的連接失??!請檢查網(wǎng)絡(luò)或IP地址!", 16
stb.Panels("state").Text = "連接失??!"
Else
mnuFileConnect.Enabled = False
Command1.Enabled = True
stb.Panels("state").Text = "連接成功!"
End If
Me.MousePointer = 0
Timer1.Enabled = False
Exit Sub
ERR:
MsgBox "連接出錯(cuò)!請檢查IP地址或網(wǎng)絡(luò)!", 16
End Sub
'=========| 菜單--退出 |=========
Private Sub mnuFileExit_Click()
Unload Me
End Sub
'=========| 菜單--設(shè)置 |=========
Private Sub mnuFileSet_Click()
frmSet.Show 1, Me
DoEvents
If blnLoginSuccess Then
mnuFileConnect.Enabled = False
Else
mnuFileConnect.Enabled = True
End If
End Sub
'============================
' WinSock數(shù)據(jù)到達(dá)
Private Sub sck_DataArrival(ByVal bytesTotal As Long)
Dim byteSckReceiveBuf() As Byte
Dim lngLenBuf As Long
Dim i As Integer
Dim strTp As String
'協(xié)商過程中,得到主機(jī)返回的命令結(jié)果
'命令執(zhí)行過程中,得到主機(jī)返回的執(zhí)行結(jié)果
sck.GetData byteSckReceiveBuf, vbByte + vbArray, bytesTotal
lngLenBuf = bytesTotal
strTp = ""
For i = 0 To lngLenBuf - 1
strTp = strTp + Chr(byteSckReceiveBuf(i))
Next i
rtb.Text = rtb.Text + vbCrLf + strTp
rtb.SelLength = Len(rtb.Text)
rtb.SelColor = &HFF00&
rtb.SelStart = Len(rtb.Text)
Text1.SetFocus
If Not blnLoginSuccess Then '一直和Unix主機(jī)協(xié)商,直到登錄成功
blnLoginSuccess = RemoteLogin(sck, strUserName, strPassword, byteSckReceiveBuf)
If blnLoginSuccess Then
Command1.Enabled = True
MsgBox "OK!遠(yuǎn)程登錄UNIX主機(jī)成功!", 48
stb.Panels("state").Text = "OK!遠(yuǎn)程登錄UNIX主機(jī)成功!"
End If
End If
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then Command1_Click
End Sub
Private Sub Timer1_Timer()
intConnectTime = intConnectTime + 1
End Sub
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -