#include #include "..\ztna.au3" Func _ParseHostPort($s, ByRef $rHost, ByRef $rPort) $rHost = "" $rPort = 1433 ; default ; Find the colon Local $pos = StringInStr($s, ":", 0, -1) ; last colon If $pos = 0 Then ; no colon -> only host $rHost = $s Else $rHost = StringLeft($s, $pos - 1) $rPort = Int(StringMid($s, $pos + 1)) If $rPort = 0 Then $rPort = 1433 ; fallback if empty or invalid EndIf EndFunc Func KillAllSSMS() Local $count = 0 Local $list = ProcessList("SSMS.exe") For $i = 1 To $list[0][0] Local $pid = $list[$i][1] ; Double-check the process really is SSMS Local $name = $list[$i][0] If StringLower($name) = "ssms.exe" Then ProcessClose($pid) $count += 1 EndIf Next Return $count EndFunc Local $pairs = GetConnectionParams() KillAllSSMS() ; -------------------------- ; Access asset parameters ; -------------------------- Local $input = $pairs["Host"] Local $user = $pairs["User"] Local $password = $pairs["Password"] Local $host, $port _ParseHostPort($input, $host, $port) ; --------------------------------- ; Applicaiton specific logic: BEGIN ; --------------------------------- ; --- config --- ; INI format expected (same folder as script): ; [app] ; exe=C:\Path\To\YourApp.exe ; trial=true ; ===== Script ===== Opt("SendKeyDelay", 20) Opt("SendKeyDownDelay", 5) Local Const $gIniPath = @ScriptDir & "\app-ssms.ini" Local Const $gSection = "app" ; Read settings Local $exe = IniRead($gIniPath, $gSection, "exe", "") If $exe = "" Then MsgBox(16, "Error", "Missing [app]/exe in " & $gIniPath) Exit 1 EndIf Local $delayms = IniRead($gIniPath, $gSection, "delayms", "") If $delayms = "" Then MsgBox(16, "Error", "Missing [app]/delayms in " & $gIniPath) Exit 1 EndIf ; If exe is a relative path, make it relative to the script folder If Not FileExists($exe) And FileExists(@ScriptDir & "\" & $exe) Then $exe = @ScriptDir & "\" & $exe EndIf ; Launch the target Local $pid = Run($exe, @ScriptDir) If @error Or $pid = 0 Then MsgBox(16, "Error", "Failed to start: " & $exe) Exit 2 EndIf Local Const $WIN_CONNECT = WinWaitActive("Connect (Preview)") Sleep($delayms) ; Enter Server Name ControlSend($WIN_CONNECT, "", "", $host) ; Switch to SQL Server Authentication Send("{TAB}") Send("{RIGHT}") ; Enter Username and Password Send("{TAB}") ControlSend($WIN_CONNECT, "", "", $user) Send("{TAB}") ControlSend($WIN_CONNECT, "", "", $password) ; Submit Sleep($delayms) Send("{ENTER}") ; --------------------------------- ; Applicaiton specific logic: END ; --------------------------------- UnblockInput()