Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- TaskID = Shell("C:putty.exe 173.194.127.210", vbMaximizedFocus)
- 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 = "SoftwareSimonTathamPuTTYSessions" & 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement