PhilHibbs Posted March 10, 2010 Share Posted March 10, 2010 (edited) This application stores a list of DataStage projects in the registry, along with check box settings for which client applications to launch for which project. The password is not stored in the registry but the server name and user name are. If you don't know what DataStage is, then this script will not be of much use to you other than to marvel at its brilliance. expandcollapse popup#include <Array.au3> #include <Constants.au3> #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <EditConstants.au3> #include <ButtonConstants.au3> #include <GUIComboBoxEx.au3> #include <Debug.au3> const $WinTitle = "DataStage Launcher" const $WinX = 50 const $WinY = 50 const $WinWidth = 340 const $WinHeight = 600 const $ProjNameX = 20 const $ProjDesignerX = 165 const $ProjDirectorX = 215 const $ProjManagerX = 265 const $RegKey = "HKCU\SOFTWARE\Capgemini\DSLaunch" const $DSRegKey = "HKLM\SOFTWARE\Ascential Software\DataStage Client\CurrentVersion" const $Attach = "Attach to Project" const $cCombo = "[CLASS:ThunderRT6ComboBox; INSTANCE:3]" const $cServer = "[CLASS:Edit; INSTANCE:1]" const $cUser = "[CLASS:ThunderRT6TextBox; INSTANCE:1]" const $cPass = "[CLASS:ThunderRT6TextBox; INSTANCE:2]" const $cProj = "[CLASS:Edit; INSTANCE:3]" const $cConnect = "[CLASS:ThunderRT6CommandButton; INSTANCE:3]" const $Clear = "{HOME}+{END}{DEL}" const $delay = 10 Global $Abort Opt('MustDeclareVars', 1) Opt("SendKeyDelay",$delay) Opt("GUIResizeMode", $GUI_DOCKALL) _Main() Func _Main() ;Initialize variables Local $DSPath, $Designer, $Director, $Manager Local $hGUI Local $msg Local $Server, $User, $Pass Local $Server_2, $User_2, $Pass_2 Local $eServer, $eUser, $ePass Local $eServer_2, $eUser_2, $ePass_2 Local $bLaunch, $bRefresh Local $bLaunch_2, $bRefresh_2 Local $bExpand, $bImpand Local $hCombobox, $hList Local $ProjectList, $Proj, $OldProj Local $Des, $Dir, $Man Local $Projects1, $Project, $Projects2 Local $Telnet, $xTelnet Local $Telnet_2, $xTelnet_2 Local $pTelnet, $hTelnet, $TelnetOutput Local $Timer, $i, $OK ; $Projects is a comma-separated \n-delimited list of projects and client flags, e.g. C1PDM_Dev,1,1,1 Local $Projects, $Boxes Local $Projects_2, $Boxes_2 ; _DebugSetup( "DSLaunch" ) $Server = RegRead( $RegKey, "Server" ) $Server_2 = RegRead( $RegKey, "Server_2" ) $User = RegRead( $RegKey, "User" ) $User_2 = RegRead( $RegKey, "User_2" ) $Telnet = RegRead( $RegKey, "Telnet" ) $Telnet_2 = RegRead( $RegKey, "Telnet_2" ) ReadProjects( "", $Projects ) ReadProjects( "_2", $Projects_2 ) $DSPath = RegRead( $DSRegKey, "Path" ) $Designer = $DSPath & "\dsdesign.exe" $Director = $DSPath & "\director.exe" $Manager = $DSPath & "\manager.exe" If Not( FileExists( $Designer ) ) Then MsgBox( 0, "Error", $Designer & " not found" ) Exit EndIf $hGUI = GUICreate( $WinTitle, $WinWidth, $WinHeight, $WinX, $WinY ) GUICtrlCreateLabel( "Server", 10, 10, 80, 15 ) $eServer = GUICtrlCreateInput( $Server, 100, 10, 100, 20 ) GUICtrlCreateLabel( "User Name", 10, 40, 80, 15 ) $eUser = GUICtrlCreateInput( $User, 100, 40, 100, 20 ) GUICtrlCreateLabel( "Password", 10, 70, 80, 15 ) $ePass = GUICtrlCreateInput( "", 100, 70, 100, 20, $ES_PASSWORD ) $bLaunch = GUICtrlCreateButton( "Launch", 220, 10, 50, 25, $BS_DEFPUSHBUTTON ) $xTelnet = GUICtrlCreateCheckbox( "Run Telnet", 100, 100, 100, 15 ) If $Telnet = 1 Then GUICtrlSetState( $xTelnet, $GUI_CHECKED ) GUICtrlCreateGroup( "Projects", 10, 130, $WinWidth-20, $WinHeight-140 ) GUICtrlCreateLabel( " Designer", 150, 130, 48, 15 ) GUICtrlCreateLabel( " Director", 200, 130, 43, 15 ) GUICtrlCreateLabel( " Manager", 250, 130, 47, 15 ) $bRefresh = GUICtrlCreateButton( "Refresh", 10, 100, 50, 25 ) If GUICtrlRead($eUser) = "" Then GUICtrlSetState( $eUser, $GUI_FOCUS ) Else GUICtrlSetState( $ePass, $GUI_FOCUS ) EndIf GUICtrlCreateLabel( "Server", 10+$WinWidth, 10, 80, 15 ) $eServer_2 = GUICtrlCreateInput( $Server_2, 100+$WinWidth, 10, 100, 20 ) GUICtrlCreateLabel( "User Name", 10+$WinWidth, 40, 80, 15 ) $eUser_2 = GUICtrlCreateInput( $User_2, 100+$WinWidth, 40, 100, 20 ) GUICtrlCreateLabel( "Password", 10+$WinWidth, 70, 80, 15 ) $ePass_2 = GUICtrlCreateInput( "", 100+$WinWidth, 70, 100, 20, $ES_PASSWORD ) $bLaunch_2 = GUICtrlCreateButton( "Launch", 220+$WinWidth, 10, 50, 25, $BS_DEFPUSHBUTTON ) $xTelnet_2 = GUICtrlCreateCheckbox( "Run Telnet", 100+$WinWidth, 100, 100, 15 ) If $Telnet_2 = 1 Then GUICtrlSetState( $xTelnet, $GUI_CHECKED ) GUICtrlCreateGroup( "Projects", 10+$WinWidth, 130, $WinWidth-20, $WinHeight-140 ) GUICtrlCreateLabel( " Designer", 150+$WinWidth, 130, 48, 15 ) GUICtrlCreateLabel( " Director", 200+$WinWidth, 130, 43, 15 ) GUICtrlCreateLabel( " Manager", 250+$WinWidth, 130, 47, 15 ) $bRefresh_2 = GUICtrlCreateButton( "Refresh", 10+$WinWidth, 100, 50, 25 ) $bExpand = GUICtrlCreateButton( ">>", $WinWidth-20-25, 10, 25, 25 ) $bImpand = GUICtrlCreateButton( "<<", $WinWidth-20-25, 10, 25, 25 ) GUICtrlSetState( $bImpand, $GUI_HIDE ) ShowProjects( $Projects, $Boxes, 0 ) ShowProjects( $Projects_2, $Boxes_2, $WinWidth ) GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE $Server = GUICtrlRead( $eServer ) $Server_2 = GUICtrlRead( $eServer_2 ) $User = GUICtrlRead( $eUser ) $User_2 = GUICtrlRead( $eUser_2 ) $Pass = GUICtrlRead( $ePass ) $Pass_2 = GUICtrlRead( $ePass_2 ) $Telnet = GUICtrlRead( $xTelnet ) $Telnet_2 = GUICtrlRead( $xTelnet_2 ) RegWrite( $RegKey, "Server", "REG_SZ", $Server ) RegWrite( $RegKey, "Server_2", "REG_SZ", $Server_2 ) RegWrite( $RegKey, "User", "REG_SZ", $User ) RegWrite( $RegKey, "User_2", "REG_SZ", $User_2 ) RegWrite( $RegKey, "Telnet", "REG_DWORD", $Telnet ) RegWrite( $RegKey, "Telnet_2", "REG_DWORD", $Telnet_2 ) CheckProjects( $Projects, $Boxes ) CheckProjects( $Projects_2, $Boxes_2 ) WriteProjects( "", $Projects ) WriteProjects( "_2", $Projects_2 ) GUIDelete($hGUI) Exit Case $msg = $bExpand _ClientResize( $hGUI, $WinWidth*2, $WinHeight ) GUICtrlSetState( $bExpand, $GUI_HIDE ) GUICtrlSetState( $bImpand, $GUI_SHOW ) Case $msg = $bImpand _ClientResize( $hGUI, $WinWidth, $WinHeight ) GUICtrlSetState( $bImpand, $GUI_HIDE ) GUICtrlSetState( $bExpand, $GUI_SHOW ) Case $msg = $bRefresh $Server = GUICtrlRead( $eServer ) $User = GUICtrlRead( $eUser ) $Pass = GUICtrlRead( $ePass ) $Telnet = GUICtrlRead( $xTelnet ) run( $Designer ) WinWait( $Attach ) SendKeepActive( $Attach ) Send( "!o!o+{TAB}+{TAB}+{TAB}" & $Server & "{TAB}" & $Clear & $User & "{TAB}" & $Pass ) $hCombobox = ControlGetHandle( WinGetHandle( $Attach ), "", $cCombo ) _GUICtrlComboBoxEx_ShowDropDown( $hCombobox, True ) _GUICtrlComboBoxEx_ShowDropDown( $hCombobox, False ) Send( "{Tab 2}", $Timer ) Send( "{Up 20}", $Timer ) $Proj = ControlGetText( $Attach, "", $cCombo ) $ProjectList = $Proj & @LF Do $OldProj = $Proj Send("{Down}") $Proj = ControlGetText( $Attach, "", $cCombo ) $ProjectList = $ProjectList & $Proj & @LF Until $OldProj = $Proj WinClose( $Attach ) CheckProjects( $Projects, $Boxes ) MergeProjects( $Projects, $ProjectList ) WriteProjects( "", $Projects ) ClearProjects( $Projects, $Boxes ) ShowProjects( $Projects, $Boxes, 0 ) Case $msg = $bRefresh_2 $Server_2 = GUICtrlRead( $eServer_2 ) $User_2 = GUICtrlRead( $eUser_2 ) $Pass_2 = GUICtrlRead( $ePass_2 ) $Telnet_2 = GUICtrlRead( $xTelnet_2 ) run( $Designer ) WinWait( $Attach ) SendKeepActive( $Attach ) Send( "!o!o+{TAB}+{TAB}+{TAB}" & $Server_2 & "{TAB}" & $Clear & $User_2 & "{TAB}" & $Pass_2 ) $hCombobox = ControlGetHandle( WinGetHandle( $Attach ), "", $cCombo ) _GUICtrlComboBoxEx_ShowDropDown( $hCombobox, True ) _GUICtrlComboBoxEx_ShowDropDown( $hCombobox, False ) Send( "{Tab 2}", $Timer ) Send( "{Up 20}", $Timer ) $Proj = ControlGetText( $Attach, "", $cCombo ) $ProjectList = $Proj & @LF Do $OldProj = $Proj Send("{Down}") $Proj = ControlGetText( $Attach, "", $cCombo ) $ProjectList = $ProjectList & $Proj & @LF Until $OldProj = $Proj WinClose( $Attach ) CheckProjects( $Projects_2, $Boxes_2 ) MergeProjects( $Projects_2, $ProjectList ) WriteProjects( "_2", $Projects_2 ) ClearProjects( $Projects_2, $Boxes_2 ) ShowProjects( $Projects_2, $Boxes_2, $WinWidth ) Case $msg = $bLaunch $Server = GUICtrlRead( $eServer ) $User = GUICtrlRead( $eUser ) $Pass = GUICtrlRead( $ePass ) $Telnet = GUICtrlRead( $xTelnet ) $Abort=False HotKeySet("{Esc}","Abort") $OK = True For $i = 0 To UBound( $Boxes ) - 1 $Proj = GUICtrlRead( $Boxes[$i][0] ) If $OK And GUICtrlRead( $Boxes[$i][1] ) = $GUI_CHECKED Then run( $Designer ) $OK = Attach( $Server, $User, $Pass, $Proj ) EndIf If $Abort Then Return If $OK And GUICtrlRead( $Boxes[$i][2] ) = $GUI_CHECKED Then run( $Director ) $OK = Attach( $Server, $User, $Pass, $Proj ) EndIf If $Abort Then Return If $OK And GUICtrlRead( $Boxes[$i][3] ) = $GUI_CHECKED Then run( $Manager ) $OK = Attach( $Server, $User, $Pass, $Proj ) EndIf If $Abort Then Return Next If GUICtrlRead( $xTelnet ) = $GUI_CHECKED Then $Telnet = 1 Else $Telnet = 0 EndIf If $Telnet Then $pTelnet = run("telnet " & $Server, @SystemDir) ;, @SW_RESTORE, $STDOUT_CHILD + $STDIN_CHILD ) Sleep( 1000 ) $hTelnet = GetProcessWin( $pTelnet ) SendKeepActive( $hTelnet, $User & @CRLF ) Sleep( 1000 ) SendKeepActive( $hTelnet, $Pass & @CRLF ) EndIf If $Abort Then Return RegWrite( $RegKey, "Server", "REG_SZ", $Server ) RegWrite( $RegKey, "User", "REG_SZ", $User ) RegWrite( $RegKey, "Telnet", "REG_DWORD", $Telnet ) CheckProjects( $Projects, $Boxes ) WriteProjects( "", $Projects ) MsgBox(0,"Done","Done") Case $msg = $bLaunch_2 $Server_2 = GUICtrlRead( $eServer_2 ) $User_2 = GUICtrlRead( $eUser_2 ) $Pass_2 = GUICtrlRead( $ePass_2 ) $Telnet_2 = GUICtrlRead( $xTelnet_2 ) $Abort=False HotKeySet("{Esc}","Abort") $OK = True For $i = 0 To UBound( $Boxes_2 ) - 1 $Proj = GUICtrlRead( $Boxes_2[$i][0] ) If $OK And GUICtrlRead( $Boxes_2[$i][1] ) = $GUI_CHECKED Then run( $Designer ) $OK = Attach( $Server_2, $User_2, $Pass_2, $Proj ) EndIf If $Abort Then Return If $OK And GUICtrlRead( $Boxes_2[$i][2] ) = $GUI_CHECKED Then run( $Director ) $OK = Attach( $Server_2, $User_2, $Pass_2, $Proj ) EndIf If $Abort Then Return If $OK And GUICtrlRead( $Boxes_2[$i][3] ) = $GUI_CHECKED Then run( $Manager ) $OK = Attach( $Server_2, $User_2, $Pass_2, $Proj ) EndIf If $Abort Then Return Next If GUICtrlRead( $xTelnet_2 ) = $GUI_CHECKED Then $Telnet_2 = 1 Else $Telnet_2 = 0 EndIf If $Telnet Then $pTelnet = run("telnet " & $Server, @SystemDir) ;, @SW_RESTORE, $STDOUT_CHILD + $STDIN_CHILD ) Sleep( 1000 ) $hTelnet = GetProcessWin( $pTelnet ) SendKeepActive( $hTelnet, $User_2 & @CRLF ) Sleep( 1000 ) SendKeepActive( $hTelnet, $Pass_2 & @CRLF ) EndIf If $Abort Then Return RegWrite( $RegKey, "Server_2", "REG_SZ", $Server_2 ) RegWrite( $RegKey, "User_2", "REG_SZ", $User_2 ) RegWrite( $RegKey, "Telnet_2", "REG_DWORD", $Telnet_2 ) CheckProjects( $Projects_2,$Boxes_2 ) WriteProjects( "_2", $Projects_2 ) MsgBox(0,"Done","Done") EndSelect WEnd EndFunc Func MergeProjects( ByRef $Projects, $New ) Dim $NewList Dim $OldList Dim $Proj, $ProjDets $NewList = StringSplit( $New, @LF, 2 ) $OldList = StringSplit( $Projects, @LF, 2 ) For $Proj In $OldList $ProjDets = StringSplit( $Proj, ",", 2 ) _ArraySearch( $NewList, $ProjDets[0] ) If @error Then $Projects = StringLeft( $Projects, StringInStr( $Projects, $ProjDets[0] ) ) & StringMid( $Projects, StringInStr( $Projects, $ProjDets[0] ) + StringLen( $ProjDets[0] ) + 7 ) EndIf Next $OldList = StringSplit( $Projects, @LF, 2 ) For $Proj In $NewList If StringLen( $Proj ) > 1 Then _ArraySearch( $OldList, $Proj,0,0,0,1 ) If @error Then MyArrayAdd1( $OldList, $Proj & ",0,0,0" ) EndIf EndIf Next _ArraySort( $OldList ) $Projects = "" For $Proj In $OldList $Projects = $Projects & $Proj & @LF Next EndFunc Func ReadProjects( $Suffix, ByRef $Projects ) $Projects = RegRead( $RegKey, "Projects" & $Suffix ) EndFunc Func CheckProjects( ByRef $Projects, ByRef $Boxes ) Dim $i $Projects = "" For $i = 0 To UBound( $Boxes ) - 1 If StringLen($Boxes[$i][0]) > 0 Then $Projects = $Projects & GUICtrlRead( $Boxes[$i][0] ) If GUICtrlRead( $Boxes[$i][1] ) = $GUI_CHECKED Then $Projects = $Projects & ",1" Else $Projects = $Projects & ",0" EndIf If GUICtrlRead( $Boxes[$i][2] ) = $GUI_CHECKED Then $Projects = $Projects & ",1" Else $Projects = $Projects & ",0" EndIf If GUICtrlRead( $Boxes[$i][3] ) = $GUI_CHECKED Then $Projects = $Projects & ",1" Else $Projects = $Projects & ",0" EndIf $Projects = $Projects & @LF EndIf Next EndFunc Func WriteProjects( $Suffix, ByRef $Projects ) RegWrite( $RegKey, "Projects" & $Suffix, "REG_SZ", $Projects ) EndFunc Func ClearProjects( ByRef $Projects, ByRef $Boxes ) Local $i For $i = 0 To UBound( $Boxes ) - 1 GUICtrlDelete( $Boxes[0][0] ) GUICtrlDelete( $Boxes[0][1] ) GUICtrlDelete( $Boxes[0][2] ) GUICtrlDelete( $Boxes[0][3] ) _ArrayDelete( $Boxes, 0 ) Next EndFunc Func ShowProjects( ByRef $Projects, ByRef $Boxes, $Offset ) Local $Proj, $ProjList, $ProjDets, $ProjBoxes, $ProjNum Local $Des, $Dir, $Man Local $temp $ProjNum = 0 $ProjList = StringSplit( $Projects, @LF, 2 ) For $Proj In $ProjList If StringInStr( $Proj, "," ) > 0 Then $ProjDets = StringSplit( $Proj, "," , 2 ) $ProjBoxes = $ProjDets $ProjBoxes[0] = GuiCtrlCreateLabel( $ProjDets[0], $ProjNameX + $Offset, 150 + ($ProjNum * 16), 100, 15 ) $ProjBoxes[1] = GUICtrlCreateCheckbox( " ", $ProjDesignerX + $Offset, 150 + ($ProjNum * 16), 15, 15 ) $ProjBoxes[2] = GUICtrlCreateCheckbox( " ", $ProjDirectorX + $Offset, 150 + ($ProjNum * 16), 15, 15 ) $ProjBoxes[3] = GUICtrlCreateCheckbox( " ", $ProjManagerX + $Offset, 150 + ($ProjNum * 16), 15, 15 ) MyArrayAdd2( $Boxes, $ProjBoxes ) If $ProjDets[1] = "1" Then GUICtrlSetState( $Boxes[$ProjNum][1], $GUI_CHECKED ) EndIf If $ProjDets[2] = "1" Then GUICtrlSetState( $Boxes[$ProjNum][2], $GUI_CHECKED ) EndIf If $ProjDets[3] = "1" Then GUICtrlSetState( $Boxes[$ProjNum][3], $GUI_CHECKED ) EndIf $ProjNum = $ProjNum + 1 EndIf Next EndFunc Func Attach( $Server, $User, $Pass, $Proj ) Local $Timer, $hControl WinWait( $Attach ) SendKeepActive( $Attach ) $hControl = ControlGetHandle( WinGetHandle( $Attach ), "", $cCombo ) If ControlGetText( $Attach, "", $cServer ) <> $Server Then ControlSend( $Attach, "", "[CLASS:Edit; INSTANCE:1]", $Clear & $Server ) EndIf If ControlGetText( $Attach, "", $cUser ) <> $User Then ControlSend( $Attach, "", "[CLASS:ThunderRT6TextBox; INSTANCE:1]", $Clear & $User ) EndIf ControlSend( $Attach, "", "[CLASS:ThunderRT6TextBox; INSTANCE:2]", $Clear & $Pass ) If ControlGetText( $Attach, "", $cProj ) <> $Proj Then ControlSend( $Attach, "", "[CLASS:Edit; INSTANCE:3]", $Clear & $Proj ) EndIf ControlSend( $Attach, "", "[CLASS:ThunderRT6CommandButton; INSTANCE:3]", "{Enter}" ) $Timer = TimerInit() While TimerDiff($Timer) < 10000 And WinExists( $Attach ) Sleep(10) WEnd If WinExists( $Attach ) Then Return False Else Return True EndIf EndFunc Func GetProcessWin( $process ) Local $WinList Local $i $WinList = WinList() For $i = 1 to $WinList[0][0] If WinGetProcess( $WinList[$i][1] ) = $process Then ; _DebugReport( $WinList[$i][0] & "," & $WinList[$i][1] ) Return $WinList[$i][1] EndIf Next EndFunc Func _ClientResize( $hWnd, $iWidth, $iHeight ) Local $rClient, $rWindow, $iDiffX, $iDiffY $rClient = _WinAPI_GetClientRect($hWnd) $rWindow = _WinAPI_GetWindowRect($hWnd) $iDiffX = (DllStructGetData($rWindow, "right") - DllStructGetData($rWindow, "left")) - DllStructGetData($rClient, "right") $iDiffY = (DllStructGetData($rWindow, "bottom") - DllStructGetData($rWindow, "top")) - DllStructGetData($rClient, "bottom") WinMove($hWnd, "", DllStructGetData($rWindow, "left"), DllStructGetData($rWindow, "top"), $iWidth + $iDiffX, $iHeight + $iDiffY) EndFunc Func MyArrayAdd1( ByRef $avArray, $vValue ) Local $iUBound = UBound($avArray) If Not(IsArray($avArray)) Or UBound($avArray, 0) <> 1 Then Dim $TempArray[1] $avArray = $TempArray $iUBound = 1 Else ReDim $avArray[$iUBound + 1] EndIf $avArray[$iUBound] = $vValue Return $iUBound EndFunc Func MyArrayAdd2(ByRef $avArray, $avValue) Local $iUBound1 = UBound($avArray) Local $iUBound2 = UBound($avValue) If Not(IsArray($avArray)) Or UBound($avArray, 0) <> 2 Then Dim $TempArray[1][$iUBound2] $avArray = $TempArray $iUBound1 = 0 Else ReDim $avArray[$iUBound1 + 1][$iUBound2] EndIf For $i = 0 To $iUBound2 - 1 $avArray[$iUBound1][$i] = $avValue[$i] Next Return $iUBound1 EndFunc ;==>_ArrayAdd Func Abort() HotKeySet("{Esc}") $Abort = True EndFunc *Update*: Now stores two sets of data for connecting with different user IDs. Edited March 19, 2010 by PhilHibbs Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now