Advertisement
Guest User

Untitled

a guest
May 26th, 2015
812
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 5.52 KB | None | 0 0
  1. #AutoIt3Wrapper_UseX64=n
  2. Opt("MustDeclareVars", 1)
  3. AutoItSetOption("WinTitleMatchMode", 3) ; EXACT_MATCH!
  4.  
  5. ;============================================================
  6. ;             PSM AutoIt Dispatcher Skeleton
  7. ;             ------------------------------
  8. ;
  9. ; Use this skeleton to create your own
  10. ; connection components integrated with the PSM.
  11. ; Areas you may want to modify are marked
  12. ; with the string "CHANGE_ME".
  13. ;
  14. ; Created : April 2013
  15. ; Cyber-Ark Software Ltd.
  16. ;============================================================
  17. #include "PSMGenericClientWrapper.au3"
  18.  
  19. ;=======================================
  20. ; Consts & Globals
  21. ;=======================================
  22. Global Const $DISPATCHER_NAME                                      = "MyDispatcherName" ; CHANGE_ME
  23. Global Const $CLIENT_EXECUTABLE                                 = "c:\VNC-Viewer-5.0.5-Windows-64bit.exe" ; CHANGE_ME
  24. Global Const $ERROR_MESSAGE_TITLE                               = "PSM " & $DISPATCHER_NAME & " Dispatcher error message"
  25. Global Const $LOG_MESSAGE_PREFIX                                = $DISPATCHER_NAME & " Dispatcher - "
  26.  
  27. Global $TargetUsername
  28. Global $TargetPassword
  29. Global $TargetAddress
  30. Global $ConnectionClientPID = 0
  31.  
  32. ;=======================================
  33. ; Code
  34. ;=======================================
  35. Exit Main()
  36.  
  37. ;=======================================
  38. ; Main
  39. ;=======================================
  40. Func Main()
  41.  
  42.     ; Init PSM Dispatcher utils wrapper
  43.     ToolTip ("Initializing...")
  44.     if (PSMGenericClient_Init() <> $PSM_ERROR_SUCCESS) Then
  45.         Error(PSMGenericClient_PSMGetLastErrorString())
  46.     EndIf
  47.  
  48.     LogWrite("successfully initialized Dispatcher Utils Wrapper")
  49.  
  50.     ; Get the dispatcher parameters
  51.     FetchSessionProperties()
  52.  
  53.     LogWrite("mapping local drives")
  54.     if (PSMGenericClient_MapTSDrives() <> $PSM_ERROR_SUCCESS) Then
  55.         Error(PSMGenericClient_PSMGetLastErrorString())
  56.     EndIf
  57.  
  58.     LogWrite("starting client application")
  59.     ToolTip ("Starting " & $DISPATCHER_NAME & "...")
  60.     $ConnectionClientPID = Run($CLIENT_EXECUTABLE)
  61.     if ($ConnectionClientPID == 0) Then
  62.         Error(StringFormat("Failed to execute process [%s]", $CLIENT_EXECUTABLE, @error))
  63.     EndIf
  64.  
  65.     ; Send PID to PSM as early as possible so recording/monitoring can begin
  66.     LogWrite("sending PID to PSM")
  67.     if (PSMGenericClient_SendPID($ConnectionClientPID) <> $PSM_ERROR_SUCCESS) Then
  68.         Error(PSMGenericClient_PSMGetLastErrorString())
  69.     EndIf
  70.  
  71.     ; ------------------
  72.     ; Handle login here! ; CHANGE_ME
  73.     ; ------------------
  74.  
  75.     ; Terminate PSM Dispatcher utils wrapper
  76.     LogWrite("Terminating Dispatcher Utils Wrapper")
  77.     PSMGenericClient_Term()
  78.  
  79.     Return $PSM_ERROR_SUCCESS
  80. EndFunc
  81.  
  82. ;==================================
  83. ; Functions
  84. ;==================================
  85. ; #FUNCTION# ====================================================================================================================
  86. ; Name...........: Error
  87. ; Description ...: An exception handler - displays an error message and terminates the dispatcher
  88. ; Parameters ....: $ErrorMessage - Error message to display
  89. ;                  $Code         - [Optional] Exit error code
  90. ; ===============================================================================================================================
  91. Func Error($ErrorMessage, $Code = -1)
  92.  
  93.     ; If the dispatcher utils DLL was already initialized, write an error log message and terminate the wrapper
  94.     if (PSMGenericClient_IsInitialized()) Then
  95.         LogWrite($ErrorMessage, True)
  96.         PSMGenericClient_Term()
  97.     EndIf
  98.  
  99.     Local $MessageFlags = BitOr(0, 16, 262144) ; 0=OK button, 16=Stop-sign icon, 262144=MsgBox has top-most attribute set
  100.  
  101.     MsgBox($MessageFlags, $ERROR_MESSAGE_TITLE, $ErrorMessage)
  102.  
  103.     ; If the connection component was already invoked, terminate it
  104.     if ($ConnectionClientPID <> 0) Then
  105.         ProcessClose($ConnectionClientPID)
  106.         $ConnectionClientPID = 0
  107.     EndIf
  108.  
  109.     Exit $Code
  110. EndFunc
  111.  
  112. ; #FUNCTION# ====================================================================================================================
  113. ; Name...........: LogWrite
  114. ; Description ...: Write a PSMWinSCPDispatcher log message to standard PSM log file
  115. ; Parameters ....: $sMessage - [IN] The message to write
  116. ;                  $LogLevel - [Optional] [IN] Defined if the message should be handled as an error message or as a trace messge
  117. ; Return values .: $PSM_ERROR_SUCCESS - Success, otherwise error - Use PSMGenericClient_PSMGetLastErrorString for details.
  118. ; ===============================================================================================================================
  119. Func LogWrite($sMessage, $LogLevel = $LOG_LEVEL_TRACE)
  120.     Return PSMGenericClient_LogWrite($LOG_MESSAGE_PREFIX & $sMessage, $LogLevel)
  121. EndFunc
  122.  
  123. ; #FUNCTION# ====================================================================================================================
  124. ; Name...........: PSMGenericClient_GetSessionProperty
  125. ; Description ...: Fetches properties required for the session
  126. ; Parameters ....: None
  127. ; Return values .: None
  128. ; ===============================================================================================================================
  129. Func FetchSessionProperties() ; CHANGE_ME
  130.     if (PSMGenericClient_GetSessionProperty("Username", $TargetUsername) <> $PSM_ERROR_SUCCESS) Then
  131.         Error(PSMGenericClient_PSMGetLastErrorString())
  132.     EndIf
  133.  
  134.     if (PSMGenericClient_GetSessionProperty("Password", $TargetPassword) <> $PSM_ERROR_SUCCESS) Then
  135.         Error(PSMGenericClient_PSMGetLastErrorString())
  136.     EndIf
  137.  
  138.     if (PSMGenericClient_GetSessionProperty("Address", $TargetAddress) <> $PSM_ERROR_SUCCESS) Then
  139.         Error(PSMGenericClient_PSMGetLastErrorString())
  140.     EndIf
  141. EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement