需要通过vba代码编辑putty的标题栏

我正在使用下面的vba代码打开一个button点击腻子屏幕。

TaskID = Shell("C:\putty.exe 173.194.127.210", vbMaximizedFocus) 

当它打开一个新的屏幕时,标题栏将包含string“173.194.127.210 – PUTTY”。 上面的代码打开一个新的屏幕时,我想通过vba代码将“173.194.127.210 – PUTTY”更改为“173.194.127.210 – HELLO”。 任何人都可以分享这样做的代码? 请注意,我不使用超级腻子。

我可以手动执行以下步骤:

  1. 右键单击打开的腻子屏幕的标题栏。
  2. 点击更改设置
  3. 点击窗口选项下的行为
  4. 将窗口标题更改为173.194.127.210 – HELLO

不幸的是,没有办法通过命令行来改变这个值。 这个值可以设置的唯一地方是在一个会话中。 查看PuTTY Configuration页面,然后单击Session分支来查看。 总是有一个叫做“默认设置”的会话,不能删除,只是显示应用程序的内部默认值。 你不能改变这些。 但是,您可以编程方式创build一个新的会话,保存窗口标题,然后使用PuTTY命令行的“-load”选项在启动应用程序时加载该会话。

会话的这些信息存储在每个用户的registry中,位于HKEY_CURRENT_USER \ Software \ SimonTatham \ PuTTY \ Sessions项下。 这里的每个密钥都会变成一个密钥名称的会话。 为了创build不太可能与用户会话冲突的会话名称,下面的代码使用名称,该名称是应用程序EXE名称,前缀为两个下划线。

您需要为窗口标题写入的registry值是“WinTitle”。 但是,您还必须为PuTTY提供“HostName”,“Protocol”和“Port”值才能正确打开。 除“端口”外的所有值都是string(REG_SZ),而“端口”是一个整数(REG_DWORD)。

 Option Explicit Private Const HKEY_CURRENT_USER As Long = &H80000001 Private Const ERROR_SUCCESS As Long = 0& Private Const REG_SZ As Long = 1 Private Const REG_DWORD As Long = 4 Private Enum REGSAM KEY_ALL_ACCESS = &HF003F KEY_CREATE_LINK = &H20 KEY_CREATE_SUB_KEY = &H4 KEY_ENUMERATE_SUB_KEYS = &H8 KEY_EXECUTE = &H20019 KEY_NOTIFY = &H10 KEY_QUERY_VALUE = &H1 KEY_READ = &H20019 KEY_SET_VALUE = &H2 KEY_WOW64_32KEY = &H200 KEY_WOW64_64KEY = &H100 KEY_WRITE = &H20006 End Enum Private Declare Function RegCloseKey Lib "Advapi32.dll" ( _ ByVal hKey As Long _ ) As Long Private Declare Function RegCreateKeyEx Lib "Advapi32.dll" Alias "RegCreateKeyExW" ( _ ByVal hKey As Long, _ ByVal lpSubKey As Long, _ ByVal Reserved As Long, _ ByVal lpClass As Long, _ ByVal dwOptions As Long, _ ByVal samDesired As REGSAM, _ ByVal lpSecurityAttributes As Long, _ ByRef phkResult As Long, _ ByRef lpdwDisposition As Long _ ) As Long Private Declare Function RegSetValueEx Lib "Advapi32.dll" Alias "RegSetValueExW" ( _ ByVal hKey As Long, _ ByVal lpValueName As Long, _ ByVal Reserved As Long, _ ByVal dwType As Long, _ ByVal lpData As Long, _ ByVal cbData As Long _ ) As Long Private Enum ConnectionType Raw Telnet Rlogin SSH End Enum Private Function OpenPutty(ByRef the_sHost As String, ByRef the_sTitle As String, ByVal enmConnectionType As ConnectionType, Optional ByVal the_nPort = -1) As Long Dim sUniqueSession As String Dim sKeyUniqueSession As String Dim sConnectionType As String Dim nPort As Long Dim hKeyUniqueSession As Long sUniqueSession = "__" & App.EXEName sKeyUniqueSession = "Software\SimonTatham\PuTTY\Sessions\" & sUniqueSession ' Provide the connection type / protocol string, and a default port value. Select Case enmConnectionType Case Raw sConnectionType = "raw" nPort = -1 Case Telnet sConnectionType = "telnet" nPort = 23 Case Rlogin sConnectionType = "rlogin" nPort = 513 Case SSH sConnectionType = "ssh" nPort = 22 End Select ' -1 indicates use the default port value. If the_nPort <> -1 Then nPort = the_nPort End If If RegCreateKeyEx(HKEY_CURRENT_USER, StrPtr(sKeyUniqueSession), 0&, 0&, 0&, KEY_SET_VALUE, 0&, hKeyUniqueSession, 0&) = ERROR_SUCCESS Then RegSetValueEx hKeyUniqueSession, StrPtr("HostName"), 0&, REG_SZ, StrPtr(the_sHost), LenB(the_sHost) RegSetValueEx hKeyUniqueSession, StrPtr("WinTitle"), 0&, REG_SZ, StrPtr(the_sTitle), LenB(the_sTitle) RegSetValueEx hKeyUniqueSession, StrPtr("Protocol"), 0&, REG_SZ, StrPtr(sConnectionType), LenB(sConnectionType) RegSetValueEx hKeyUniqueSession, StrPtr("PortNumber"), 0&, REG_DWORD, VarPtr(nPort), LenB(nPort) RegCloseKey hKeyUniqueSession End If OpenPutty = Shell(App.Path & "\putty.exe -load """ & sUniqueSession & """", vbMaximizedFocus) End Function Private Sub Command1_Click() OpenPutty "192.168.1.5", "My custom title", Telnet End Sub 
 Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Public Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long Sub Main() On Error Resume Next hwindows = FindWindow(vbNullString, "Microsoft Works Calendar") Ret = SetWindowText(hwindows, "Calandar") End Sub