linux teraterm ,windows remote desktop用户名 密码自用输入 快捷login && batファイル生成VBA

linux     teraterm

—————————————————————-

; sample macro of Tera Term
;
; File: security.ttl
; Description: auto login with SSH2 protocol
; Environment: generic
; Update: 2018/04/18
; Author: author

USERNAME = ‘bbbbb’
PASSWORD = ‘aaaaaa’

; ③コマンド組立
COMMAND = ‘192.168.xx.xxx’
strconcat COMMAND ‘:22 /ssh /2 /protocol=IPv4 /auth=password /user=’
strconcat COMMAND USERNAME
strconcat COMMAND ‘ /passwd=’
strconcat COMMAND PASSWORD

; ④接続
connect COMMAND

; ログ開始
getdate LOG_NAME ‘%Y%m%d_%H%M%S__IP_&h.log’
FULLPATH=’C:\_D\teratermlog\’
strconcat FULLPATH LOG_NAME
logopen FULLPATH 0 1

; ⑤マクロ終了
end


windows  batch remote desktop

@Echo off
Set SERVER=192.168.xx.xx
Set USERNAME=xxx
Set PASSWORD=xxxxxxx
Cmdkey /generic:TERMSRV/%SERVER% /user:%USERNAME% /pass:%PASSWORD%
Start mstsc /v:%SERVER%
Timeout 1
Cmdkey /delete:TERMSRV/%SERVER%


batファイル生成VBA 

下記のexcelで シート名「shortcutList」

batファイル出力先 C:\Users\hyousk\Desktop\新しいフォルダー
サーバ情報 出力batファイル名 IP ログインID パスワード
【基盤】デスクトップ#DSK3_192.168.xx.xx 192.168.xx.xx xxxxx xxxxxx

下記のマクロでbatファイル生成

Sub Macro1()

‘ Macro1 Macro

‘ Keyboard Shortcut: Ctrl+f

savePath = Worksheets(“shortcutList”).Cells(1, 2)
For i = 3 To Worksheets(“shortcutList”).Cells(Rows.Count, “B”).End(xlUp).Row
hostNm = Worksheets(“shortcutList”).Cells(i, 2)
ipAdd = Worksheets(“shortcutList”).Cells(i, 3)
userNm = Worksheets(“shortcutList”).Cells(i, 4)
passWd = Worksheets(“shortcutList”).Cells(i, 5)

aa = makeText(savePath, hostNm, ipAdd, userNm, passWd)

Next
MsgBox “batに書き出しました”

End Sub

Function makeText(ByVal savePath As String, ByVal hostNm As String, ByVal ipAdd As String, ByVal userNm As String, ByVal passWd As String)

Dim datFile As String
datFile = savePath & “\” & hostNm & “.bat”

Open datFile For Output As #1

Print #1, “@Echo off”
Print #1, “Set SERVER=” & ipAdd
Print #1, “Set USERNAME=” & userNm
Print #1, “Set PASSWORD=” & passWd
Print #1, ” ”
Print #1, “Cmdkey /generic:TERMSRV/%SERVER% /user:%USERNAME% /pass:%PASSWORD%”
Print #1, “Start mstsc /v:%SERVER%”
Print #1, “Timeout 1”
Print #1, “Cmdkey /delete:TERMSRV/%SERVER%”
Print #1, ” ”
Close #1

End Function

Add a Comment

您的电子邮箱地址不会被公开。 必填项已用*标注