Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.67 KB | None | 0 0
  1. TaskID = Shell("C:putty.exe 173.194.127.210", vbMaximizedFocus)
  2.  
  3. Option Explicit
  4.  
  5. Private Const HKEY_CURRENT_USER As Long = &H80000001
  6.  
  7. Private Const ERROR_SUCCESS As Long = 0&
  8.  
  9. Private Const REG_SZ As Long = 1
  10. Private Const REG_DWORD As Long = 4
  11.  
  12. Private Enum REGSAM
  13. KEY_ALL_ACCESS = &HF003F
  14. KEY_CREATE_LINK = &H20
  15. KEY_CREATE_SUB_KEY = &H4
  16. KEY_ENUMERATE_SUB_KEYS = &H8
  17. KEY_EXECUTE = &H20019
  18. KEY_NOTIFY = &H10
  19. KEY_QUERY_VALUE = &H1
  20. KEY_READ = &H20019
  21. KEY_SET_VALUE = &H2
  22. KEY_WOW64_32KEY = &H200
  23. KEY_WOW64_64KEY = &H100
  24. KEY_WRITE = &H20006
  25. End Enum
  26.  
  27. Private Declare Function RegCloseKey Lib "Advapi32.dll" ( _
  28. ByVal hKey As Long _
  29. ) As Long
  30.  
  31. Private Declare Function RegCreateKeyEx Lib "Advapi32.dll" Alias "RegCreateKeyExW" ( _
  32. ByVal hKey As Long, _
  33. ByVal lpSubKey As Long, _
  34. ByVal Reserved As Long, _
  35. ByVal lpClass As Long, _
  36. ByVal dwOptions As Long, _
  37. ByVal samDesired As REGSAM, _
  38. ByVal lpSecurityAttributes As Long, _
  39. ByRef phkResult As Long, _
  40. ByRef lpdwDisposition As Long _
  41. ) As Long
  42.  
  43. Private Declare Function RegSetValueEx Lib "Advapi32.dll" Alias "RegSetValueExW" ( _
  44. ByVal hKey As Long, _
  45. ByVal lpValueName As Long, _
  46. ByVal Reserved As Long, _
  47. ByVal dwType As Long, _
  48. ByVal lpData As Long, _
  49. ByVal cbData As Long _
  50. ) As Long
  51.  
  52. Private Enum ConnectionType
  53. Raw
  54. Telnet
  55. Rlogin
  56. SSH
  57. End Enum
  58.  
  59. Private Function OpenPutty(ByRef the_sHost As String, ByRef the_sTitle As String, ByVal enmConnectionType As ConnectionType, Optional ByVal the_nPort = -1) As Long
  60.  
  61. Dim sUniqueSession As String
  62. Dim sKeyUniqueSession As String
  63. Dim sConnectionType As String
  64. Dim nPort As Long
  65. Dim hKeyUniqueSession As Long
  66.  
  67. sUniqueSession = "__" & App.EXEName
  68. sKeyUniqueSession = "SoftwareSimonTathamPuTTYSessions" & sUniqueSession
  69.  
  70. ' Provide the connection type / protocol string, and a default port value.
  71. Select Case enmConnectionType
  72. Case Raw
  73. sConnectionType = "raw"
  74. nPort = -1
  75. Case Telnet
  76. sConnectionType = "telnet"
  77. nPort = 23
  78. Case Rlogin
  79. sConnectionType = "rlogin"
  80. nPort = 513
  81. Case SSH
  82. sConnectionType = "ssh"
  83. nPort = 22
  84. End Select
  85.  
  86. ' -1 indicates use the default port value.
  87. If the_nPort <> -1 Then
  88. nPort = the_nPort
  89. End If
  90.  
  91. If RegCreateKeyEx(HKEY_CURRENT_USER, StrPtr(sKeyUniqueSession), 0&, 0&, 0&, KEY_SET_VALUE, 0&, hKeyUniqueSession, 0&) = ERROR_SUCCESS Then
  92. RegSetValueEx hKeyUniqueSession, StrPtr("HostName"), 0&, REG_SZ, StrPtr(the_sHost), LenB(the_sHost)
  93. RegSetValueEx hKeyUniqueSession, StrPtr("WinTitle"), 0&, REG_SZ, StrPtr(the_sTitle), LenB(the_sTitle)
  94. RegSetValueEx hKeyUniqueSession, StrPtr("Protocol"), 0&, REG_SZ, StrPtr(sConnectionType), LenB(sConnectionType)
  95. RegSetValueEx hKeyUniqueSession, StrPtr("PortNumber"), 0&, REG_DWORD, VarPtr(nPort), LenB(nPort)
  96. RegCloseKey hKeyUniqueSession
  97. End If
  98.  
  99. OpenPutty = Shell(App.Path & "putty.exe -load """ & sUniqueSession & """", vbMaximizedFocus)
  100.  
  101. End Function
  102.  
  103. Private Sub Command1_Click()
  104. OpenPutty "192.168.1.5", "My custom title", Telnet
  105. End Sub
  106.  
  107. Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
  108.  
  109. Public Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long
  110.  
  111. Sub Main()
  112. On Error Resume Next
  113. hwindows = FindWindow(vbNullString, "Microsoft Works Calendar")
  114. Ret = SetWindowText(hwindows, "Calandar")
  115. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement