Jump to content

DSA.MSC


LucasZ
 Share

Recommended Posts

  • Developers
5 minutes ago, molsicor said:

Hello Lucas, can you share your script ? 

The member hasn't been around since 2018 so maybe it better you show your script and explain your issue?

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Hello, here is my script that didn't work ; 

#AutoIt3Wrapper_UseX64=n
Opt("MustDeclareVars", 1)
AutoItSetOption("WinTitleMatchMode", 3) ; EXACT_MATCH!

;============================================================
;             PSM AutoIt Dispatcher Skeleton
;             ------------------------------
;
; Use this skeleton to create your own
; connection components integrated with the PSM.
; Areas you may want to modify are marked
; with the string "CHANGE_ME".
;
; Created : April 2013
; Cyber-Ark Software Ltd.
;============================================================
#include "PSMGenericClientWrapper.au3"
#include <File.au3>
#include <FileConstants.au3>
;#include <BlockInputEx.au3>
;=======================================
; Consts & Globals
;=======================================
Global Const $DISPATCHER_NAME                                      = "AD Users and Computers MMC" ; CHANGE_ME
;Global Const $LOGIN_WEBPAGE                                        = "https://" & $TargetAddress ; CHANGE_ME
Global Const $CLIENT_EXECUTABLE                                 = "dnsmgmt.msc" ; CHANGE_ME
;Global Const $CLIENT_EXECUTABLE                                    = "c:\Program Files (x86)\Internet Explorer\iexplore.exe " &  $LOGIN_WEBPAGE ; CHANGE_ME
Global Const $ERROR_MESSAGE_TITLE                               = "PSM " & $DISPATCHER_NAME & " Dispatcher error message"
Global Const $LOG_MESSAGE_PREFIX                                = $DISPATCHER_NAME & " Dispatcher - "

Global $TargetUsername
Global $TargetPassword
Global $TargetAddress
Global $ConnectionClientPID = 0

;=======================================
; Code
;=======================================
Exit Main()

;=======================================
; Main
;=======================================
Func Main()

    ; Init PSM Dispatcher utils wrapper
    ToolTip ("Initializing...")
    if (PSMGenericClient_Init() <> $PSM_ERROR_SUCCESS) Then
        Error(PSMGenericClient_PSMGetLastErrorString())
    EndIf

    LogWrite("successfully initialized Dispatcher Utils Wrapper")

    ; Get the dispatcher parameters
    FetchSessionProperties()

    LogWrite("mapping local drives")
    if (PSMGenericClient_MapTSDrives() <> $PSM_ERROR_SUCCESS) Then
        Error(PSMGenericClient_PSMGetLastErrorString())
    EndIf

    LogWrite("starting client application")
    ToolTip ("Startinsssg " & $DISPATCHER_NAME & "...")
    ;BlockInput(1)
;Run("cmd")
;WinWait("C:\Windows\SYSTEM32\cmd.exe")
;WinActivate("C:\Windows\SYSTEM32\cmd.exe")
;send("cd AppData/Roaming/SAP/Common")
;sleep("500")
;send("{ENTER}")
;send("xcopy C:\Users\Default\AppData\Roaming\SAP\Common\SAPUILandscape.xml /R /Y")
;send("{ENTER}")



;_BlockInputEx(1)
RunAs($TargetUsername, "ilove" , $TargetPassword, 2, 'C:\Windows\System32\mmc.exe "C:\Windows\System32\dsa.msc"', "", @SW_SHOWMAXIMIZED)
WinWait("[CLASS:ConsoleWindowClass]")
;send("C:\Users\admin\Desktop\dsa.msc")
send("{ENTER}")
Sleep(20000)
WinActivate("[CLASS:ConsoleWindowClass]")
WinClose("[CLASS:ConsoleWindowClass]")
;Sleep(300)
;send("exit")
;send("{ENTER}")
$ConnectionClientPID=WinGetProcess("Active Directory Users and Computers")
;Sleep(7000)

;_BlockInputEx(0)
    if ($ConnectionClientPID == 0) Then
        Error(StringFormat("Failed to execute process [%s]",$CLIENT_EXECUTABLE, @error))
    EndIf

; Send PID to PSM as early as possible so recording/monitoring can begin
    LogWrite("sending PID to PSM")
    ;Sleep(3000)
    if (PSMGenericClient_SendPID($ConnectionClientPID) <> $PSM_ERROR_SUCCESS) Then
        Error(PSMGenericClient_PSMGetLastErrorString())
    EndIf


    ;Diger islemleri buraya yaz
     ;Terminate PSM Dispatcher utils wrapper
    LogWrite("Terminating Dispatcher Utils Wrapper")
    PSMGenericClient_Term()

    Return $PSM_ERROR_SUCCESS
EndFunc

;==================================
; Functions
;==================================
; #FUNCTION# ====================================================================================================================
; Name...........: Error
; Description ...: An exception handler - displays an error message and terminates the dispatcher
; Parameters ....: $ErrorMessage - Error message to display
;                  $Code         - [Optional] Exit error code
; ===============================================================================================================================
Func Error($ErrorMessage, $Code = -1)

    ; If the dispatcher utils DLL was already initialized, write an error log message and terminate the wrapper
    if (PSMGenericClient_IsInitialized()) Then
        LogWrite($ErrorMessage, True)
        PSMGenericClient_Term()
    EndIf

    Local $MessageFlags = BitOr(0, 16, 262144) ; 0=OK button, 16=Stop-sign icon, 262144=MsgBox has top-most attribute set

    MsgBox($MessageFlags, $ERROR_MESSAGE_TITLE, $ErrorMessage)

    ; If the connection component was already invoked, terminate it
    if ($ConnectionClientPID <> 0) Then
        ProcessClose($ConnectionClientPID)
        $ConnectionClientPID = WinGetProcess(_IEPropertyGet($oIE, "hwnd"))
        ProcessClose($ConnectionClientPID)
        $ConnectionClientPID = 0
    EndIf

    Exit $Code
EndFunc

; #FUNCTION# ====================================================================================================================
; Name...........: LogWrite
; Description ...: Write a PSMWinSCPDispatcher log message to standard PSM log file
; Parameters ....: $sMessage - [IN] The message to write
;                  $LogLevel - [Optional] [IN] Defined if the message should be handled as an error message or as a trace messge
; Return values .: $PSM_ERROR_SUCCESS - Success, otherwise error - Use PSMGenericClient_PSMGetLastErrorString for details.
; ===============================================================================================================================
Func LogWrite($sMessage, $LogLevel = $LOG_LEVEL_TRACE)
    Return PSMGenericClient_LogWrite($LOG_MESSAGE_PREFIX & $sMessage, $LogLevel)
EndFunc

; #FUNCTION# ====================================================================================================================
; Name...........: PSMGenericClient_GetSessionProperty
; Description ...: Fetches properties required for the session
; Parameters ....: None
; Return values .: None
; ===============================================================================================================================
Func FetchSessionProperties() ; CHANGE_ME
    if (PSMGenericClient_GetSessionProperty("Username", $TargetUsername) <> $PSM_ERROR_SUCCESS) Then
        Error(PSMGenericClient_PSMGetLastErrorString())
    EndIf

    if (PSMGenericClient_GetSessionProperty("Password", $TargetPassword) <> $PSM_ERROR_SUCCESS) Then
        Error(PSMGenericClient_PSMGetLastErrorString())
    EndIf

    if (PSMGenericClient_GetSessionProperty("PSMRemoteMachine", $TargetAddress) <> $PSM_ERROR_SUCCESS) Then
        Error(PSMGenericClient_PSMGetLastErrorString())
    EndIf

EndFunc

 

Link to comment
Share on other sites

On 1/18/2018 at 9:23 PM, LucasZ said:

My current script is:

Dsamsc()

Func Dsamsc()

   Local $sUserName = "actualusername"
   Local $sPassword = "actualpassword>"

   ;Command to run batch file that will run dsa.msc as target user from CyberArk
   Local $iPID = RunAs($sUserName, @ComputerName, $sPassword, 2, 'C:\Windows\System32\mmc.exe "C:\Windows\System32\dsa.msc"', "", @SW_SHOWMAXIMIZED)

   WinWait("[CLASS:MMCMainFrame]", "", 10)

   ProcessClose($iPID)

EndFunc

 

LucasZ's script, with the "RunAs" line changed to reflect the "logon flag as a 2" missing parameter.
Can't help more.

Link to comment
Share on other sites

  • Developers
21 minutes ago, molsicor said:

Therefore, can you share all script ? because It related other part of code, I think. I got the error that I attached

Please just post the text of the message and your whole script when you need help on the syntax. Also installing the Full version of SciTE4AutoIt3 will help a great deal as that will do the basic syntax checking for you.

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Hello I think its not about syntax. Here is full of code; and I add screen shot of error

#AutoIt3Wrapper_UseX64=n
Opt("MustDeclareVars", 1)
AutoItSetOption("WinTitleMatchMode", 3) ; EXACT_MATCH!

;============================================================
;             PSM AutoIt Dispatcher Skeleton
;             ------------------------------
;
; Use this skeleton to create your own
; connection components integrated with the PSM.
; Areas you may want to modify are marked
; with the string "CHANGE_ME".
;
; Created : April 2013
; Cyber-Ark Software Ltd.
;============================================================
#include "PSMGenericClientWrapper.au3"
#include <File.au3>
#include <FileConstants.au3>
#RequireAdmin
;#include <BlockInputEx.au3>
;=======================================
; Consts & Globals
;=======================================
Global Const $DISPATCHER_NAME                                      = "AD Users and Computers MMC" ; CHANGE_ME
Global Const $CLIENT_EXECUTABLE                                 = "dnsmgmt.msc" ; CHANGE_ME
Global Const $ERROR_MESSAGE_TITLE                               = "PSM " & $DISPATCHER_NAME & " Dispatcher error message"
Global Const $LOG_MESSAGE_PREFIX                                = $DISPATCHER_NAME & " Dispatcher - "

Global $TargetUsername
Global $TargetPassword
Global $TargetAddress
Global $ConnectionClientPID = 0

;=======================================
; Code
;=======================================
Exit Main()

;=======================================
; Main
;=======================================
Func Main()

    ; Init PSM Dispatcher utils wrapper
    ToolTip ("Initializing...")
    if (PSMGenericClient_Init() <> $PSM_ERROR_SUCCESS) Then
        Error(PSMGenericClient_PSMGetLastErrorString())
    EndIf

    LogWrite("successfully initialized Dispatcher Utils Wrapper")

    ; Get the dispatcher parameters
    FetchSessionProperties()

    LogWrite("mapping local drives")
    if (PSMGenericClient_MapTSDrives() <> $PSM_ERROR_SUCCESS) Then
        Error(PSMGenericClient_PSMGetLastErrorString())
    EndIf

    LogWrite("starting client application")
    ToolTip ("Startinsssg " & $DISPATCHER_NAME & "...")
    

Dsamsc()

Func Dsamsc()

   Local $sUserName = "actualusername"
   Local $sPassword = "actualpassword>"

   ;Command to run batch file that will run dsa.msc as target user from CyberArk
   Local $iPID = RunAs($sUserName, @ComputerName, $sPassword, 2, 'C:\Windows\System32\mmc.exe "C:\Windows\System32\dsa.msc"', "", @SW_SHOWMAXIMIZED)

   WinWait("[CLASS:MMCMainFrame]", "", 10)

   ProcessClose($iPID)

EndFunc



WinActivate("[CLASS:ConsoleWindowClass]")
WinClose("[CLASS:ConsoleWindowClass]")


$ConnectionClientPID=WinGetProcess("Active Directory Users and Computers")

    if ($ConnectionClientPID == 0) Then
        Error(StringFormat("Failed to execute process [%s]",$CLIENT_EXECUTABLE, @error))
    EndIf

; Send PID to PSM as early as possible so recording/monitoring can begin
    LogWrite("sending PID to PSM")
    ;Sleep(3000)
    if (PSMGenericClient_SendPID($ConnectionClientPID) <> $PSM_ERROR_SUCCESS) Then
        Error(PSMGenericClient_PSMGetLastErrorString())
    EndIf


    
     ;Terminate PSM Dispatcher utils wrapper
    LogWrite("Terminating Dispatcher Utils Wrapper")
    PSMGenericClient_Term()

    Return $PSM_ERROR_SUCCESS
EndFunc

;==================================
; Functions
;==================================
; #FUNCTION# ====================================================================================================================
; Name...........: Error
; Description ...: An exception handler - displays an error message and terminates the dispatcher
; Parameters ....: $ErrorMessage - Error message to display
;                  $Code         - [Optional] Exit error code
; ===============================================================================================================================
Func Error($ErrorMessage, $Code = -1)

    ; If the dispatcher utils DLL was already initialized, write an error log message and terminate the wrapper
    if (PSMGenericClient_IsInitialized()) Then
        LogWrite($ErrorMessage, True)
        PSMGenericClient_Term()
    EndIf

    Local $MessageFlags = BitOr(0, 16, 262144) ; 0=OK button, 16=Stop-sign icon, 262144=MsgBox has top-most attribute set

    MsgBox($MessageFlags, $ERROR_MESSAGE_TITLE, $ErrorMessage)

    ; If the connection component was already invoked, terminate it
    if ($ConnectionClientPID <> 0) Then
        ProcessClose($ConnectionClientPID)
        $ConnectionClientPID = WinGetProcess(_IEPropertyGet($oIE, "hwnd"))
        ProcessClose($ConnectionClientPID)
        $ConnectionClientPID = 0
    EndIf

    Exit $Code
EndFunc

; #FUNCTION# ====================================================================================================================
; Name...........: LogWrite
; Description ...: Write a PSMWinSCPDispatcher log message to standard PSM log file
; Parameters ....: $sMessage - [IN] The message to write
;                  $LogLevel - [Optional] [IN] Defined if the message should be handled as an error message or as a trace messge
; Return values .: $PSM_ERROR_SUCCESS - Success, otherwise error - Use PSMGenericClient_PSMGetLastErrorString for details.
; ===============================================================================================================================
Func LogWrite($sMessage, $LogLevel = $LOG_LEVEL_TRACE)
    Return PSMGenericClient_LogWrite($LOG_MESSAGE_PREFIX & $sMessage, $LogLevel)
EndFunc

; #FUNCTION# ====================================================================================================================
; Name...........: PSMGenericClient_GetSessionProperty
; Description ...: Fetches properties required for the session
; Parameters ....: None
; Return values .: None
; ===============================================================================================================================
Func FetchSessionProperties() ; CHANGE_ME
    if (PSMGenericClient_GetSessionProperty("Username", $TargetUsername) <> $PSM_ERROR_SUCCESS) Then
        Error(PSMGenericClient_PSMGetLastErrorString())
    EndIf

    if (PSMGenericClient_GetSessionProperty("Password", $TargetPassword) <> $PSM_ERROR_SUCCESS) Then
        Error(PSMGenericClient_PSMGetLastErrorString())
    EndIf

    if (PSMGenericClient_GetSessionProperty("PSMRemoteMachine", $TargetAddress) <> $PSM_ERROR_SUCCESS) Then
        Error(PSMGenericClient_PSMGetLastErrorString())
    EndIf

EndFunc

line67.JPG

Link to comment
Share on other sites

Your "Main()" function is awaiting "EndFunc" termination before beginning a new "Func".

Could you try a minimal script where you just attempt to connect through cyberark, then run MMC, then exit? i.e replace for the moment your script with only LucasZ's quoted one?

Dsamsc()

Func Dsamsc()

   Local $sUserName = "actualusername"
   Local $sPassword = "actualpassword>"

   ;Command to run batch file that will run dsa.msc as target user from CyberArk
   Local $iPID = RunAs($sUserName, @ComputerName, $sPassword, 2, 'C:\Windows\System32\mmc.exe "C:\Windows\System32\dsa.msc"', "", @SW_SHOWMAXIMIZED)

   WinWait("[CLASS:MMCMainFrame]", "", 10)

   ProcessClose($iPID)

EndFunc

#cs
#AutoIt3Wrapper_UseX64=n
Opt("MustDeclareVars", 1)
AutoItSetOption("WinTitleMatchMode", 3) ; EXACT_MATCH!

;============================================================
;             PSM AutoIt Dispatcher Skeleton
;             ------------------------------
;
; Use this skeleton to create your own
; connection components integrated with the PSM.
; Areas you may want to modify are marked
; with the string "CHANGE_ME".
;
; Created : April 2013
; Cyber-Ark Software Ltd.
;============================================================
#include "PSMGenericClientWrapper.au3"
#include <File.au3>
#include <FileConstants.au3>
#RequireAdmin
;#include <BlockInputEx.au3>
;=======================================
; Consts & Globals
;=======================================
Global Const $DISPATCHER_NAME                                      = "AD Users and Computers MMC" ; CHANGE_ME
Global Const $CLIENT_EXECUTABLE                                 = "dnsmgmt.msc" ; CHANGE_ME
Global Const $ERROR_MESSAGE_TITLE                               = "PSM " & $DISPATCHER_NAME & " Dispatcher error message"
Global Const $LOG_MESSAGE_PREFIX                                = $DISPATCHER_NAME & " Dispatcher - "

Global $TargetUsername
Global $TargetPassword
Global $TargetAddress
Global $ConnectionClientPID = 0

;=======================================
; Code
;=======================================
Exit Main()

;=======================================
; Main
;=======================================
Func Main()

    ; Init PSM Dispatcher utils wrapper
    ToolTip ("Initializing...")
    if (PSMGenericClient_Init() <> $PSM_ERROR_SUCCESS) Then
        Error(PSMGenericClient_PSMGetLastErrorString())
    EndIf

    LogWrite("successfully initialized Dispatcher Utils Wrapper")

    ; Get the dispatcher parameters
    FetchSessionProperties()

    LogWrite("mapping local drives")
    if (PSMGenericClient_MapTSDrives() <> $PSM_ERROR_SUCCESS) Then
        Error(PSMGenericClient_PSMGetLastErrorString())
    EndIf

    LogWrite("starting client application")
    ToolTip ("Startinsssg " & $DISPATCHER_NAME & "...")
    
WinActivate("[CLASS:ConsoleWindowClass]")
WinClose("[CLASS:ConsoleWindowClass]")


$ConnectionClientPID=WinGetProcess("Active Directory Users and Computers")

    if ($ConnectionClientPID == 0) Then
        Error(StringFormat("Failed to execute process [%s]",$CLIENT_EXECUTABLE, @error))
    EndIf

; Send PID to PSM as early as possible so recording/monitoring can begin
    LogWrite("sending PID to PSM")
    ;Sleep(3000)
    if (PSMGenericClient_SendPID($ConnectionClientPID) <> $PSM_ERROR_SUCCESS) Then
        Error(PSMGenericClient_PSMGetLastErrorString())
    EndIf


    
     ;Terminate PSM Dispatcher utils wrapper
    LogWrite("Terminating Dispatcher Utils Wrapper")
    PSMGenericClient_Term()

    Return $PSM_ERROR_SUCCESS
EndFunc

;==================================
; Functions
;==================================
; #FUNCTION# ====================================================================================================================
; Name...........: Error
; Description ...: An exception handler - displays an error message and terminates the dispatcher
; Parameters ....: $ErrorMessage - Error message to display
;                  $Code         - [Optional] Exit error code
; ===============================================================================================================================
Func Error($ErrorMessage, $Code = -1)

    ; If the dispatcher utils DLL was already initialized, write an error log message and terminate the wrapper
    if (PSMGenericClient_IsInitialized()) Then
        LogWrite($ErrorMessage, True)
        PSMGenericClient_Term()
    EndIf

    Local $MessageFlags = BitOr(0, 16, 262144) ; 0=OK button, 16=Stop-sign icon, 262144=MsgBox has top-most attribute set

    MsgBox($MessageFlags, $ERROR_MESSAGE_TITLE, $ErrorMessage)

    ; If the connection component was already invoked, terminate it
    if ($ConnectionClientPID <> 0) Then
        ProcessClose($ConnectionClientPID)
        $ConnectionClientPID = WinGetProcess(_IEPropertyGet($oIE, "hwnd"))
        ProcessClose($ConnectionClientPID)
        $ConnectionClientPID = 0
    EndIf

    Exit $Code
EndFunc

; #FUNCTION# ====================================================================================================================
; Name...........: LogWrite
; Description ...: Write a PSMWinSCPDispatcher log message to standard PSM log file
; Parameters ....: $sMessage - [IN] The message to write
;                  $LogLevel - [Optional] [IN] Defined if the message should be handled as an error message or as a trace messge
; Return values .: $PSM_ERROR_SUCCESS - Success, otherwise error - Use PSMGenericClient_PSMGetLastErrorString for details.
; ===============================================================================================================================
Func LogWrite($sMessage, $LogLevel = $LOG_LEVEL_TRACE)
    Return PSMGenericClient_LogWrite($LOG_MESSAGE_PREFIX & $sMessage, $LogLevel)
EndFunc

; #FUNCTION# ====================================================================================================================
; Name...........: PSMGenericClient_GetSessionProperty
; Description ...: Fetches properties required for the session
; Parameters ....: None
; Return values .: None
; ===============================================================================================================================
Func FetchSessionProperties() ; CHANGE_ME
    if (PSMGenericClient_GetSessionProperty("Username", $TargetUsername) <> $PSM_ERROR_SUCCESS) Then
        Error(PSMGenericClient_PSMGetLastErrorString())
    EndIf

    if (PSMGenericClient_GetSessionProperty("Password", $TargetPassword) <> $PSM_ERROR_SUCCESS) Then
        Error(PSMGenericClient_PSMGetLastErrorString())
    EndIf

    if (PSMGenericClient_GetSessionProperty("PSMRemoteMachine", $TargetAddress) <> $PSM_ERROR_SUCCESS) Then
        Error(PSMGenericClient_PSMGetLastErrorString())
    EndIf

EndFunc
#ce

 

Edited by Denver
Code addition.
Link to comment
Share on other sites

  • Developers
20 minutes ago, molsicor said:

Hello I think its not about syntax.

Yes it is ....  as explained ... and if you would have followed my advice, au3check would have told you!

...also, as requested, please do not post pictures of error message but only the text.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Theoretically, the RunAs command is a way to enter username/password in an unencrypted way.

If you have the MMC command that shows up, then it asks for credentials, verify you wrote the actual credentials in the "actualusername" and "actualpassword>" areas.

They are meant to be surrounded by double quotes (as in Local $sPassword = "Pw0rd"), and I warmly welcome you to ask for more general AutoIT help if you have more general AutoIT questions.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...