Jump to content

My script is closing without error message, just closing


Recommended Posts

When I use the compiled script, in some machines (not all), the script is closing without error message, just closing. This problem is not occouring in the development file.

The code is running until the loop mode and few seconds after the screen appear, the code crash.

Can anyone help me?

Global $Form_MATLAB_Profiles = GUICreate("EngTools: " & $AppName & " - " & EnvGet("EngTools_Env") & " - " & EnvGet("MATLAB_USERNAME"), 725, 713, -1, -1, BitOR($WS_SYSMENU, $WS_CAPTION, $WS_POPUP, $WS_POPUPWINDOW, $WS_BORDER, $WS_CLIPSIBLINGS), $WS_EX_APPWINDOW);, BitOR($WS_CAPTION,  $WS_CLIPSIBLINGS), $WS_EX_APPWINDOW)

#Region ## GRUPO WELCOME ##

$Group_Welcome = GUICtrlCreateGroup("", 0, 0, 721, 41);Grupo Welcome
$Label_WelcomeText = GUICtrlCreateLabel("Loading . . .", 3, 9, 715, 28, $SS_CENTER)
GUICtrlSetFont($Label_WelcomeText, 14, 800, 0, "MS Sans Serif")

GUICtrlSetData($Label_WelcomeText, "Good Morning - " & $UserPartialName)
GUICtrlSetColor($Label_WelcomeText, $Color_G)

If @HOUR > "11" Then
    GUICtrlSetData($Label_WelcomeText, "Good Afternoon - " & $UserPartialName)
    GUICtrlSetColor($Label_WelcomeText, $Color_B)
EndIf
If @HOUR > "18" Then
    GUICtrlSetData($Label_WelcomeText, "Good Evening - " & $UserPartialName)
EndIf
GUICtrlCreateGroup("", -99, -99, 1, 1);Fecha o grupo Welcome ($Group_Welcome)

#EndRegion ## GRUPO WELCOME ##

GUICtrlCreateGroup(" TOOLBOXES ", 0, 45, 721, 260);Grupo TOOLBOXES
Global $TreeView_Profiles = GUICtrlCreateListView("", 1, 58, 718, 245, -1, BitOR($LVS_EX_CHECKBOXES, $LVS_EX_GRIDLINES, $LVS_EX_FLATSB, $LVS_EX_SNAPTOGRID))
GUICtrlSetStyle($TreeView_Profiles, BitOR($LVS_LIST, $LVS_SHOWSELALWAYS)); set this ListView to LVS_ICON-style cause LVS_ICON = 0x0000
GUICtrlCreateGroup("", -99, -99, 1, 1);Fecha o grupo TOOLBOXES

$Button_CheckToolBox = GUICtrlCreateButton("Search Profile", 5, 310, 110, 40)
GUICtrlSetTip($Button_CheckToolBox, "Search for a available profile.")
$hImage_Button_CheckToolBox = _GUIImageList_Create(32, 32, 5, 3)
_GUIImageList_AddIcon($hImage_Button_CheckToolBox, $hImage_Search, 0, True)
_GUICtrlButton_SetImageList($Button_CheckToolBox, $hImage_Button_CheckToolBox)

$Button_ClearToolBox = GUICtrlCreateButton("Uncheck All", 135, 310, 110, 40)
GUICtrlSetTip(-1, "Search for a available profile.")
$hImage_Button_ClearToolBox = _GUIImageList_Create(32, 32, 5, 3)
_GUIImageList_AddIcon($hImage_Button_ClearToolBox, $hImage_Clear, 0, True)
_GUICtrlButton_SetImageList($Button_ClearToolBox, $hImage_Button_ClearToolBox)

$Button_Close = GUICtrlCreateButton("EXIT", 640, 310, 70, 40, $BS_MULTILINE)
$hImage_Button_Close = _GUIImageList_Create(32, 32, 5, 3)
_GUIImageList_AddIcon($hImage_Button_Close, $hImage_Exit, 0, True)
_GUICtrlButton_SetImageList($Button_Close, $hImage_Button_Close)

$Label_Wait = GUICtrlCreateLabel("Please Wait . . .", 260, 310, 245, 41)
GUICtrlSetFont($Label_Wait, 24, 800, 0, "MS Sans Serif")
GUICtrlSetColor($Label_Wait, 0xFF0000)
GUICtrlSetState($Label_Wait, $GUI_HIDE)

$ListView_Aval_Profiles = GUICtrlCreateListView("ID|% FREE|Nº TOOLBOXES", 0, 360, 250, 315, BitOR($LVS_NOLABELWRAP, $LVS_SINGLESEL, $LVS_SORTASCENDING, $TVS_CHECKBOXES), BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
_GUICtrlListView_JustifyColumn($ListView_Aval_Profiles, 0, 2)
_GUICtrlListView_JustifyColumn($ListView_Aval_Profiles, 1, 2)
_GUICtrlListView_JustifyColumn($ListView_Aval_Profiles, 2, 2)

;~ _GUICtrlListView_SetExtendedListViewStyle($ListView_Aval_Profiles, BitOR($LVS_EX_FLATSB, $LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_ONECLICKACTIVATE))


_GUICtrlListView_SetColumnWidth($ListView_Aval_Profiles, 0, $LVSCW_AUTOSIZE_USEHEADER)
_GUICtrlListView_SetColumnWidth($ListView_Aval_Profiles, 1, $LVSCW_AUTOSIZE_USEHEADER)
_GUICtrlListView_SetColumnWidth($ListView_Aval_Profiles, 2, $LVSCW_AUTOSIZE_USEHEADER)

$LabelRefresh = GUICtrlCreateLabel("There is no available profile containing all selected toolboxes.", 250, 310, 250, 40, $SS_CENTER)
GUICtrlSetColor($LabelRefresh, $Color_R)
GUICtrlSetFont($LabelRefresh, 10, 500)
GUICtrlSetState($LabelRefresh, $GUI_HIDE)

GUICtrlCreateGroup(" PROFILE TOOLBOX LIST ", 510, 355, 210, 315, $BS_CENTER);Grupo FEATURE TOOLBOX LIST
$ListToolBox = GUICtrlCreateList("", 519, 372, 194, 301, BitOR($LBS_NOSEL, $WS_VSCROLL, $LBS_SORT))
GUICtrlSetColor($ListToolBox, 0x9999)
GUICtrlCreateGroup("", -99, -99, 1, 1);Fecha o grupo FEATURE TOOLBOX LIST

GUICtrlCreateGroup(" OPTIONS ", 260, 355, 240, 210, $BS_CENTER);Grupo OPTIONS

$Button_RunMatlab = GUICtrlCreateButton("CHECKOUT PROFILE #", 320, 380, 110, 50, $BS_MULTILINE)
$hImage_Button_RunMatlab = _GUIImageList_Create(32, 32, 5, 3)
_GUIImageList_AddIcon($hImage_Button_RunMatlab, $hImage, 0, True)
_GUICtrlButton_SetImageList($Button_RunMatlab, $hImage_Button_RunMatlab)
GUICtrlSetState($Button_RunMatlab, $GUI_DISABLE)

$Button_CreateShortCut = GUICtrlCreateButton("Create Desktop Shortcut", 265, 440, 110, 50, $BS_MULTILINE)
$hImage_Button_CreateShortCut = _GUIImageList_Create(32, 32, 5, 3)
_GUIImageList_AddIcon($hImage_Button_CreateShortCut, $hImage_ShortCut, 0, True)
_GUICtrlButton_SetImageList($Button_CreateShortCut, $hImage_Button_CreateShortCut)
GUICtrlSetState($Button_CreateShortCut, $GUI_DISABLE)

$Button_GetCMDLine = GUICtrlCreateButton("Get Direct Command Line", 385, 440, 110, 50, $BS_MULTILINE)
$hImage_Button_GetCMDLine = _GUIImageList_Create(32, 32, 5, 3)
_GUIImageList_AddIcon($hImage_Button_GetCMDLine, $hImage_CMDLine, 0, True)
_GUICtrlButton_SetImageList($Button_GetCMDLine, $hImage_Button_GetCMDLine)
GUICtrlSetState($Button_GetCMDLine, $GUI_DISABLE)

$Button_Help = GUICtrlCreateButton("HELP", 320, 500, 110, 50, $BS_MULTILINE)
$hImage_Button_Help = _GUIImageList_Create(32, 32, 5, 3)
_GUIImageList_AddIcon($hImage_Button_Help, $hImage_Help, 0, True)
_GUICtrlButton_SetImageList($Button_Help, $hImage_Button_Help)

GUICtrlCreateGroup("", -99, -99, 1, 1);Fecha o grupo OPTIONS

GUICtrlCreateGroup("", 260, 675, 460, 35);Grupo ABOUT
$LabelDMUInfra = GUICtrlCreateLabel("Desenvolvido pelo Time de Desenv. e Gestão de Ambientes CAD/CAE - Versão: " & FileGetVersion(@AutoItExe), 265, 688, 450, 20, $SS_CENTER)
GUICtrlSetState($LabelDMUInfra, $GUI_DISABLE)
GUICtrlCreateGroup("", -99, -99, 1, 1);Fecha o grupo ABOUT

;~ $pic = GUICreate("", 130, 100, 310, 590, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $Form_MATLAB_Profiles)
;~ GUICtrlCreatePic($hImage_EMBLogo, 0, 0, 130, 100)

;Montagem da tela de profiles
$ProfilesSection = IniReadSection($MATLAB_GLOBAL_SETTINGS, "PROFILES")
Dim $ProfilesArray[300]


If $ProfilesSection[0][0] > 0 Then
    $i = 0

    $ProfileBuffer = ";SistemicUser_1;SistemicUser_2;SistemicUser_3;(...);"
    $CountProfiles = 0
    While 1
        $j = 1
        $Profile_Splited = StringSplit($ProfilesSection[$i][1], ";")
        While 1

            If Not StringInStr($ProfileBuffer, ";" & $Profile_Splited[$j] & ";") And $Profile_Splited[$j] <> "" Then
                $CountProfiles = $CountProfiles + 1
                $ProfileBuffer = $ProfileBuffer & $Profile_Splited[$j] & ";"
                $hText = StringUpper($Profile_Splited[$j])

                If $hText <> "" Then
                    _ArrayAdd($ProfilesArray, $hText)
                EndIf
            EndIf
            If $j = $Profile_Splited[0] Then ExitLoop
            $j = $j + 1
        WEnd
        If $i = $ProfilesSection[0][0] Then ExitLoop
        $i = $i + 1
    WEnd

    _ArraySort($ProfilesArray, 0)
    $ProfilesArray_String = _ArrayToString($ProfilesArray, "|")
    $ProfilesArray_String = StringReplace($ProfilesArray_String, "||", "")

    $ProfilesArray = StringSplit($ProfilesArray_String, "|")
    $CountProfiles = 1

    While 1
        If $ProfilesArray[$CountProfiles] <> "" Then
            $ProfileItem[$CountProfiles] = GUICtrlCreateListViewItem($ProfilesArray[$CountProfiles], $TreeView_Profiles)
            If StringInStr($Toolboxes, $ProfilesArray[$CountProfiles]) Or $ProfilesArray[$CountProfiles] = "MATLAB" Then
                GUICtrlSetState($ProfileItem[$CountProfiles], $GUI_CHECKED)
                GUICtrlSetBkColor($ProfileItem[$CountProfiles], $Color_G)
            Else
                GUICtrlSetState($ProfileItem[$CountProfiles], $GUI_UNCHECKED)
                GUICtrlSetBkColor($ProfileItem[$CountProfiles], 0xFFFFFF)
            EndIf
            GUICtrlSetImage($TreeView_Profiles, $hImage, 1)
        EndIf
        If $CountProfiles = $ProfilesArray[0] Then ExitLoop
        $CountProfiles = $CountProfiles + 1
    WEnd

EndIf

$SelectedCollum = ""
$CountTreeView_Profiles = 0


GUISetState(@SW_SHOW, $Form_MATLAB_Profiles)

If String($Debug) = String("1") Then
    _FileWriteLog($TraceFile, "Tela criada")
EndIf





Do

    $nMsg = GUIGetMsg(1)


    Switch $nMsg[0]

        Case $GUI_EVENT_PRIMARYUP
            If _GUICtrlListView_GetSelectedIndices($ListView_Aval_Profiles, False) <> $SelectedCollum Then

                $SelectedCollum = _GUICtrlListView_GetSelectedIndices($ListView_Aval_Profiles, False)

                If String($Debug) = String("1") Then
                    _FileWriteLog($TraceFile, "$SelectedCollum: " & $SelectedCollum)
                EndIf

                If $SelectedCollum <> "" And $SelectedCollum <> $SelectedCollum_Buffer Then
                    $SelectedCollum_Buffer = $SelectedCollum
                    $SelectedRow = _GUICtrlListView_GetItemText($ListView_Aval_Profiles, Number($SelectedCollum), 0)
                    If Number($SelectedRow) < Number(10) Then
                        $SelectedRow = String("00") & String($SelectedRow)
                    Else
                        $SelectedRow = String("0") & String($SelectedRow)
                    EndIf
                    $ProfilesList = IniRead($MATLAB_GLOBAL_SETTINGS, "PROFILES", $SelectedRow, "")
                    $ProfilesList_Split = StringSplit($ProfilesList, ";")
                    _GUICtrlListBox_ResetContent($ListToolBox)
                    If $ProfilesList_Split[0] > 0 Then
                        $CountProfiles_Splited = 1
                        While 1
                            GUICtrlSetData($ListToolBox, StringUpper($ProfilesList_Split[$CountProfiles_Splited]))
                            If $CountProfiles_Splited = $ProfilesList_Split[0] Then ExitLoop
                            $CountProfiles_Splited = $CountProfiles_Splited + 1
                        WEnd

                    EndIf
                    GUICtrlSetData($Button_RunMatlab, "CHECKOUT PROFILE #" & $SelectedRow)
                    _GUICtrlListBox_Sort($ListToolBox)
                    _GUICtrlListBox_Sort($ListToolBox)
                    _GUICtrlListView_ClickItem($ListView_Aval_Profiles, $SelectedCollum, "left", False, 1)

                EndIf
                If $SelectedRow = "" Then
                    GUICtrlSetState($Button_RunMatlab, $GUI_DISABLE)
                    GUICtrlSetData($Button_RunMatlab, "CHECKOUT PROFILE #")
                    GUICtrlSetState($Button_CreateShortCut, $GUI_DISABLE)
                    GUICtrlSetState($Button_GetCMDLine, $GUI_DISABLE)
                Else
                    GUICtrlSetState($Button_RunMatlab, $GUI_ENABLE)
                    GUICtrlSetState($Button_CreateShortCut, $GUI_ENABLE)
                    GUICtrlSetState($Button_GetCMDLine, $GUI_ENABLE)
                EndIf


            EndIf



        Case $Button_GetCMDLine
            GUICtrlSetState($LabelRefresh, $GUI_HIDE)
            If String($Debug) = String("1") Then
                _FileWriteLog($TraceFile, "$Button_GetCMDLine")
            EndIf
            If $SelectedRow <> "" Then
                $InputBox_Shortcut = InputBox("EngTools " & $AppName & " Command Line", "Press OK button to copy to clipboard", $EngToolsDir & "\EngTools.exe " & "/runCAE /programCAE:" & EnvGet("EngTools_Program") & " /envCAE:" & EnvGet("EngTools_Env") & " /cae /CAEParam:/profile:" & $SelectedRow)
                If $InputBox_Shortcut <> "" Then
                    ClipPut($InputBox_Shortcut)
                    _FileWriteLog($LogFile, $UserName & " - " & @ComputerName & " - Clipboard Copy: " & $InputBox_Shortcut)
                    MsgBox(262208, "EngTools " & $AppName & " Command Line", "The command line was copied to clipboard")
                EndIf
            EndIf

        Case $Button_CreateShortCut
            GUICtrlSetState($LabelRefresh, $GUI_HIDE)
            If String($Debug) = String("1") Then
                _FileWriteLog($TraceFile, "$Button_CreateShortCut")
            EndIf
            If $SelectedRow <> "" Then
                $InputBox_Shortcut = InputBox("EngTools Shortcut Name", "Type a EngTools Shortcut Name", "EngTools - " & $AppName & " " & EnvGet("EngTools_Env") & " Profile #" & $SelectedRow)
                GUICtrlSetState($Label_Wait, $GUI_SHOW)
                If $InputBox_Shortcut <> "" Then
                    $ShortCut = FileCreateShortcut($EngToolsDir & "\EngTools.exe", @DesktopDir & "\" & $InputBox_Shortcut, $EngToolsDir, "/runCAE /programCAE:" & EnvGet("EngTools_Program") & " /envCAE:" & EnvGet("EngTools_Env") & " /cae /CAEParam:/profile:" & $SelectedRow, $InputBox_Shortcut)
                    If $ShortCut = 1 Then
                        Sleep(1000)
                        If FileExists(@DesktopDir & "\" & $InputBox_Shortcut & "*") Then
                            GUICtrlSetState($Label_Wait, $GUI_HIDE)
                            _FileWriteLog($LogFile, $UserName & " - " & @ComputerName & " - Shortcut created: " & $InputBox_Shortcut)
                            MsgBox(262208, "Shortcut Created", "The shortcut was sucessfuly created")
                        EndIf
                    EndIf
                EndIf
            EndIf
            GUICtrlSetState($Label_Wait, $GUI_HIDE)

        Case $Button_Help
            If String($Debug) = String("1") Then
                _FileWriteLog($TraceFile, "$Button_Help")
            EndIf
            GUICtrlSetState($Label_Wait, $GUI_SHOW)
            ShellExecute(@ScriptDir & "\HELP.PDF")
            _FileWriteLog($LogFile, $UserName & " - " & @ComputerName & " - Help started")
            Sleep(2000)
            GUICtrlSetState($Label_Wait, $GUI_HIDE)

        Case $Button_RunMatlab
            GUICtrlSetState($LabelRefresh, $GUI_HIDE)
            If String($Debug) = String("1") Then
                _FileWriteLog($TraceFile, "$Button_RunMatlab")
            EndIf
            GUICtrlSetState($Label_Wait, $GUI_SHOW)
            GUICtrlSetState($Button_RunMatlab, $GUI_DISABLE)
            $Count = 0
            $Feature_Buffer = ""
            While 1
                If String(GUICtrlRead($ProfileItem[$Count], 1)) = String("1") Then
                    $Feature_Buffer = $Feature_Buffer & GUICtrlRead($ProfileItem[$Count]) & ";"
                EndIf
                If $Count = $CountProfiles Then ExitLoop
                $Count = $Count + 1
            WEnd
            IniWrite($LocalSettings, "Matlab", "ToolBoxes", $Feature_Buffer)

            If $SelectedRow <> "" Then
                _FileWriteLog($LogFile, $UserName & " - " & @ComputerName & " - " & $AppName & " Started - Profile: " & $SelectedRow & " - Application: " & $Application)
                _RunMatlab($SelectedRow, $Application)
            EndIf
            GUICtrlSetState($Label_Wait, $GUI_HIDE)

        Case $Button_ClearToolBox
            GUICtrlSetState($LabelRefresh, $GUI_HIDE)
            If String($Debug) = String("1") Then
                _FileWriteLog($TraceFile, "$Button_ClearToolBox")
            EndIf
            GUICtrlSetState($Label_Wait, $GUI_SHOW)
            $ProfileSearch = 0
            $SelectedCollum_Buffer = ""
            $SelectedCollum = ""
            $SelectedRow = ""
            GUICtrlSetState($Button_RunMatlab, $GUI_DISABLE)
            GUICtrlSetData($Button_RunMatlab, "CHECKOUT PROFILE #")
            GUICtrlSetState($Button_CreateShortCut, $GUI_DISABLE)
            GUICtrlSetState($Button_GetCMDLine, $GUI_DISABLE)
            _GUICtrlListBox_ResetContent($ListToolBox)
            _GUICtrlListView_DeleteAllItems($ListView_Aval_Profiles)

            $Count = 0
            While 1
                GUICtrlSetState($ProfileItem[$Count], $GUI_UNCHECKED)
                GUICtrlSetBkColor($ProfileItem[$Count], 0xFFFFFF)
                If $Count = $CountProfiles Then ExitLoop
                $Count = $Count + 1
            WEnd
            GUICtrlSetState($Label_Wait, $GUI_HIDE)


        Case $Button_CheckToolBox
            GUICtrlSetState($LabelRefresh, $GUI_HIDE)
            If String($Debug) = String("1") Then
                _FileWriteLog($TraceFile, "$Button_CheckToolBox")
            EndIf
            GUICtrlSetState($Label_Wait, $GUI_SHOW)
            $ProfileSearch = 0
            $SelectedCollum_Buffer = ""
            $SelectedCollum = ""
            _CheckToolBoxButton()
            $SelectedCollum_Buffer = ""
            $SelectedCollum = ""
            GUICtrlSetState($Label_Wait, $GUI_HIDE)

        Case $GUI_EVENT_CLOSE
            If String($Debug) = String("1") Then
                _FileWriteLog($TraceFile, "$GUI_EVENT_CLOSE")
            EndIf
            Exit
        Case $Button_Close
            If String($Debug) = String("1") Then
                _FileWriteLog($TraceFile, "$Button_Close")
            EndIf
            Exit

    EndSwitch
    
    
Until $nMsg[0] = $GUI_EVENT_CLOSE



Func _CheckToolBoxButton()
    If String($Debug) = String("1") Then
        _FileWriteLog($TraceFile, "Entrei no modo de verificação do Toolbox")
    EndIf
    If String($Debug) = String("1") Then
        _FileWriteLog($TraceFile, "_CheckToolBoxButton()")
    EndIf
    $Timer_Refresh = TimerInit()
    _GUICtrlListBox_ResetContent($ListToolBox)
    _GUICtrlListView_DeleteAllItems($ListView_Aval_Profiles)
    $Count = 0
    $Feature_Buffer = ""
    While 1
        If String(GUICtrlRead($ProfileItem[$Count], 1)) = String("1") Then
            $Feature_Buffer = $Feature_Buffer & GUICtrlRead($ProfileItem[$Count]) & "|"
            GUICtrlSetBkColor($ProfileItem[$Count], $Color_G)
        Else
            GUICtrlSetBkColor($ProfileItem[$Count], 0xFFFFFF)
            GUICtrlSetState($ProfileItem[$Count], $GUI_NOFOCUS)
        EndIf
        If $Count = $CountProfiles Then ExitLoop
        $Count = $Count + 1
    WEnd

    IniWrite($LocalSettings, "Matlab", "ToolBoxes", StringReplace($Feature_Buffer, "|", ";"))

    $Count_Name = 1
    $Profile_Name = ""
    While 1
        If $ProfilesSection[$Count_Name][0] <> "#ProfileID" Then
            $Profile_Name = $Profile_Name & $ProfilesSection[$Count_Name][0] & "|"
        EndIf
        If $Count_Name = $ProfilesSection[0][0] Then ExitLoop
        $Count_Name = $Count_Name + 1
    WEnd
    $Profile_Name = StringTrimRight($Profile_Name, 1)
    $Feature_Buffer = StringTrimRight($Feature_Buffer, 1);Guarda o nome das Features que foram selecionadas
    $Feature_Buffer_Splited = StringSplit($Feature_Buffer, "|")
    If $Feature_Buffer_Splited[0] > 0 Then
        $Count_Profile = 1
        While 1
            $ProfileSplit = StringSplit($Profile_Name, "|")
            If $ProfileSplit[0] > 0 Then
                $Count_Name = 1
                $Profile_Name = ""
                While 1
                    $ProfileINIContent = IniRead($MATLAB_GLOBAL_SETTINGS, "PROFILES", $ProfileSplit[$Count_Name], "")
                    If StringInStr($ProfileINIContent, $Feature_Buffer_Splited[$Count_Profile]) Then
                        $Profile_Name = $Profile_Name & $ProfileSplit[$Count_Name] & "|"
                    EndIf
                    If $Count_Name = $ProfileSplit[0] Then ExitLoop
                    $Count_Name = $Count_Name + 1
                WEnd
            EndIf
            If $Count_Profile = $Feature_Buffer_Splited[0] Then ExitLoop
            $Count_Profile = $Count_Profile + 1
        WEnd
    EndIf

    If $Profile_Name <> "" Then
        $ProfileSearch = 1;Habilita o auto-refresh
        $Profile_Name = StringTrimRight($Profile_Name, 1)
        $Profile_Name_Splited = StringSplit($Profile_Name, "|")
        If $Profile_Name_Splited[0] > 0 Then
            $Count_Name = 1
            While 1
                $ProfileToolboxes = IniRead($MATLAB_GLOBAL_SETTINGS, "PROFILES", $Profile_Name_Splited[$Count_Name], "")
                $ProfileToolboxes_Count = StringSplit($ProfileToolboxes, ";")
                $Profile_SistemicUsers = IniRead($MATLAB_GLOBAL_SETTINGS, "SISTEMIC_USERS", $Profile_Name_Splited[$Count_Name], "")
                $Profile_SistemicUsers_TotalCount = StringSplit($Profile_SistemicUsers, ";")
                $Profile_SistemicUsers_Buffer = ""
                If $Profile_SistemicUsers_TotalCount[0] > 0 Then;Verifica o a quantidade de usuários sistemicos da feature estão em uso
                    $Count_SistemicUsers = 1
                    While 1
                        If Not FileExists($LockDirectory & "\" & $Profile_SistemicUsers_TotalCount[$Count_SistemicUsers] & ".ini") Then
                            $Profile_SistemicUsers_Buffer = $Profile_SistemicUsers_Buffer & $Profile_SistemicUsers_TotalCount[$Count_SistemicUsers] & "|"
                        EndIf
                        If $Count_SistemicUsers = $Profile_SistemicUsers_TotalCount[0] Then ExitLoop
                        $Count_SistemicUsers = $Count_SistemicUsers + 1
                    WEnd
                EndIf

                $Profile_SistemicUsers_Buffer = StringTrimRight($Profile_SistemicUsers_Buffer, 1)
                $Profile_SistemicUsers_FreeCount = StringSplit($Profile_SistemicUsers_Buffer, "|")
                If Not StringInStr($Profile_SistemicUsers_Buffer, "eng") Then
                    $Profile_SistemicUsers_FreeCount[0] = 0
                EndIf
                $InUsePercent = 100 - (100 * ($Profile_SistemicUsers_TotalCount[0] - $Profile_SistemicUsers_FreeCount[0])) / $Profile_SistemicUsers_TotalCount[0]
                $ListView_Checkout_[$Count_Name] = GUICtrlCreateListViewItem($Profile_Name_Splited[$Count_Name] & "|" & Round($InUsePercent, 1) & "%|" _
                                                                & $ProfileToolboxes_Count[0], $ListView_Aval_Profiles)
                If $Count_Name = $Profile_Name_Splited[0] Then ExitLoop
                $Count_Name = $Count_Name + 1
            WEnd
            $ListView_Checkout_[0] = $Count_Name
            $B_DESCENDING = False
            _GUICtrlListView_SimpleSort($ListView_Aval_Profiles, $B_DESCENDING, 2)
            $Count_Name = 0

            While 1
                $ItemText = _GUICtrlListView_GetItemText($ListView_Aval_Profiles, $Count_Name, 1)
                $ItemText = StringTrimRight($ItemText, 1)
                If Number($ItemText) > Number(50) Then
                    GUICtrlSetBkColor($ListView_Checkout_[$Count_Name + 1], $Color_G)
                Else
                    GUICtrlSetBkColor($ListView_Checkout_[$Count_Name + 1], $Color_Y)
                EndIf
                If Number($ItemText) = Number(0) Then
                    GUICtrlSetBkColor($ListView_Checkout_[$Count_Name + 1], $Color_R)
                EndIf
                If $Count_Name = $ListView_Checkout_[0] Then ExitLoop
                $Count_Name = $Count_Name + 1
            WEnd
            $Profile_Name = ""
        Else
            GUICtrlSetState($LabelRefresh, $GUI_SHOW)
        EndIf
    Else
        GUICtrlSetState($LabelRefresh, $GUI_SHOW)
    EndIf
    _GUICtrlListView_SetItemState($ListView_Aval_Profiles, 0, $LVIS_FOCUSED, $LVIS_FOCUSED)
    _GUICtrlListView_SetItemState($ListView_Aval_Profiles, 0, $LVIS_SELECTED, $LVIS_SELECTED)



EndFunc  ;==>_CheckToolBoxButton

-----------------------------------------------------------------To a lot of people, the Sky is the limit. To person who love the aviation, the sky is the your own home.

Link to comment
Share on other sites

It because I post only the main code.

Follow the full code:

#cs ----------------------------------------------------------------------------
    
    AutoIt Version: 3.3.0.0
    Author:      Fabricio Zambroni
    
    Script Function:
    Run Matlab in selected profile
    
#ce ----------------------------------------------------------------------------


;### Bibliotecas ###
#include <GUIConstantsEx.au3>
#include <GuiButton.au3>
#include <GuiImageList.au3>
#include <GuiTreeView.au3>
#include <GuiListView.au3>
#include <GuiListBox.au3>

#include <EditConstants.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <ListBoxConstants.au3>
#include <EditConstants.au3>

#include <Array.au3>
#include <File.au3>

;### AutoIt Options ###
Opt("TrayIconHide", 1);0=show, 1=Hide
Opt("TrayIconDebug", 0);0=no info, 1=debug line info
Opt("TrayAutoPause", 0);0=no info, 1=debug line info
Opt("TrayMenuMode", 1);0=no info, 1=debug line info
Opt("MustDeclareVars", 1);0=no info, 1=debug line info
Opt("WinWaitDelay", 350);0=no info, 1=debug line info
Opt("GUIEventOptions", 1);0=no info, 1=debug line info
;~ Opt("OnExitFunc",_OnExit())

;### DECLARAÇÕES ###
Global $Application, $Button_CheckToolBox, $Button_ClearToolBox, $Button_Close, $Button_CreateShortCut, $Button_GetCMDLine, $Button_Help, $Button_ReplaceMatlabEXE, $Button_RestoreMatlabEXE, $Button_RunMatlab
Global $Count, $CountProfiles, $CountProfiles_Splited, $CountTreeView_Profiles, $Count_Name, $Count_Profile, $Count_SistemicUsers
Global $FeatureID, $Feature_Buffer_Splited, $FileLocalConfig, $FullCmdLine, $FullCmdLine_Splited
Global $Group_Welcome, $InUsePercent, $InputBox_Shortcut, $ItemText, $Kill
Global $Label_Wait, $Label_WelcomeText, $ListToolBox, $ListView_Aval_Profiles, $LogFile_Local, $PID, $ProcMsg, $ProfileBuffer, $ProfileINIContent, $ProfileInUse
Global $ProfileSplit, $ProfileToolboxes, $ProfileToolboxes_Count, $Profile_Name, $Profile_Name_Splited, $Profile_SistemicUsers, $Profile_SistemicUsers_Buffer, $Profile_SistemicUsers_FreeCount, $Profile_SistemicUsers_TotalCount
Global $Profile_Splited, $ProfilesArray_String, $ProfilesList, $ProfilesList_Split, $ProfilesSection, $RunCommand, $ShortCut, $SistemicUser, $SistemicUserData, $SistemicUserDataSplit
Global $SistemicUser_CheckOut, $SistemicUser_Monitor, $SistemicUser_Number, $SistemicUser_Return, $Timer, $UserFullName_splited, $begin, $cmdlineraw, $hImage_Button_CheckToolBox, $hImage_Button_ClearToolBox, $hImage_Button_Close
Global $hImage_Button_CreateShortCut, $hImage_Button_GetCMDLine, $hImage_Button_Help, $hImage_Button_ReplaceMatlabEXE, $hImage_Button_RestoreMatlabEXE, $hImage_Button_RunMatlab, $hText
Global $i, $iMsgBoxAnswer, $j, $nMsg, $pic, $Debug, $Profile, $LabelRefresh, $Timer_Refresh, $Timer_Refresh2, $time, $CountDebug, $Timer_Read, $LabelDMUInfra


;### main ###


Global $StandAloneMode = 0
Global $MATLAB_GLOBAL_SETTINGS = @ScriptDir & "\MATLAB-GLOBAL-SETTINGS.INI"
Global $TraceFile = "\\Nfscad05\audit_sdd\EngTools_Log\MatlabStarter\Debug\" & StringUpper(@UserName) & ".log"
If FileExists($TraceFile) Then
    $Debug = String("1")
    $CountDebug = 0
Else
    $Debug = String("0")
EndIf

;### Variáveis globais diversas ###
Global $EngToolsDir = IniRead($MATLAB_GLOBAL_SETTINGS, "Settings", "EngToolsDir", "");Path do EngTools
Global $ProfileItem[250]
Global $ListView_Checkout_[40]
Global $LockDirectory = IniRead($MATLAB_GLOBAL_SETTINGS, "Settings", "LockDirectory", "10");Path do arquivo de Lock
Global $AutoRefresh = IniRead($MATLAB_GLOBAL_SETTINGS, "Settings", "AutoRefresh", "0");Tempo de auto-refresh (0=disable)
$AutoRefresh = $AutoRefresh * 1000
ConsoleWrite("$AutoRefresh: " & $AutoRefresh & @CRLF)
Global $Feature_Buffer = ""
Global $SelectedRow = ""
Global $SelectedCollum = ""
Global $SelectedCollum_Buffer = ""
Global $ProfileSearch = 0;Habilita o auto refresh de profiles
Global $B_DESCENDING = True;Seta a ordenação dos profiles disponíveis pela quantidade de toolboxes

;### Variáveis de customização da tela ###
Global $Color_R = IniRead($MATLAB_GLOBAL_SETTINGS, "Settings", "Color_R", "");Define o padrão de cor vermelho
Global $Color_G = IniRead($MATLAB_GLOBAL_SETTINGS, "Settings", "Color_G", "");Define o padrão de cor verde
Global $Color_Y = IniRead($MATLAB_GLOBAL_SETTINGS, "Settings", "Color_Y", "");Define o padrão de cor amarelo
Global $Color_B = IniRead($MATLAB_GLOBAL_SETTINGS, "Settings", "Color_B", "");Define o padrão de cor Azul

;### Variáveis de imagens utilizadas ###
Global $hImage = IniRead($MATLAB_GLOBAL_SETTINGS, "Settings", "hImage", "");Imagem: Lista de toolboxes
Global $hImage_Clear = IniRead($MATLAB_GLOBAL_SETTINGS, "Settings", "hImage_Clear", "");Imagem: limpar features
Global $hImage_Search = IniRead($MATLAB_GLOBAL_SETTINGS, "Settings", "hImage_Search", "");Imagem: Procurar toolboxes
Global $hImage_ShortCut = IniRead($MATLAB_GLOBAL_SETTINGS, "Settings", "hImage_ShortCut", "");Imagem: Botão create Shortcut
Global $hImage_CMDLine = IniRead($MATLAB_GLOBAL_SETTINGS, "Settings", "hImage_CMDLine", "");Imagem: Botão Direct path
Global $hImage_EMBLogo = IniRead($MATLAB_GLOBAL_SETTINGS, "Settings", "hImage_EMBLogo", "");Imagem: Embraer 40 anos
Global $hImage_ReplaceMatlabEXE = IniRead($MATLAB_GLOBAL_SETTINGS, "Settings", "hImage_ReplaceMatlabEXE", "");Imagem: Embraer 40 anos
Global $hImage_RestoreMatlabEXE = IniRead($MATLAB_GLOBAL_SETTINGS, "Settings", "hImage_RestoreMatlabEXE", "");Imagem: Embraer 40 anos
Global $hImage_Help = IniRead($MATLAB_GLOBAL_SETTINGS, "Settings", "hImage_Help", "");Imagem: Embraer 40 anos
Global $hImage_Exit = IniRead($MATLAB_GLOBAL_SETTINGS, "Settings", "hImage_Exit", "");Imagem: Embraer 40 anos

;### Variáveis globais do FlexLM e Daemon Embraer ###
Global $MyFlexLMDLL = IniRead($MATLAB_GLOBAL_SETTINGS, "Settings", "MyFlexLMDLL", "")
Global $MyFlexLMServer = IniRead($MATLAB_GLOBAL_SETTINGS, "Settings", "MyFlexLMServer", "")
Global $MyFlexLMVersion = IniRead($MATLAB_GLOBAL_SETTINGS, "Settings", "MyFlexLMVersion", "")

;### Variáveis de configuração do ambiente ###
Global $UserName = StringUpper(@UserName)
EnvSet("MATLAB_USERNAME", $UserName)
Global $RunPath = EnvGet("MATLAB_RunPath")
Global $AppName = EnvGet("AppName")
If $AppName = "" Then
    $AppName = "MATLAB"
EndIf

If String($Debug) = String("1") Then
    _FileWriteLog($TraceFile, "==========================================================================" & @CRLF & "Username: " & $UserName & @CRLF & "$RunPath: " & $RunPath & @CRLF & "$AppName: " & $AppName)
EndIf


Global $LocalPath = IniRead(@ScriptDir & "\Settings.ini", "settings", "localpath", "C:\Embraer\EngTools\");Define o local aonde as configurações do usuário serão gravadas.
Global $LocalSettings = $LocalPath & "\" & $UserName & ".ini";Arquivo de configuração do usuário
Global $LogFile = IniRead($MATLAB_GLOBAL_SETTINGS, "Settings", "LogPath", @TempDir)
$LogFile = $LogFile & "\" & $UserName & ".log"

;### Variáveis de configuração de usuário ###
Global $UserPartialName = "";Primeiro nome do usuário
Global $UserFullName = IniRead($LocalSettings, "config", "UserFullName", "")
Global $Toolboxes = IniRead($LocalSettings, "Matlab", "ToolBoxes", "")
If $UserFullName = "" Then
    $UserFullName = $UserName
    $UserPartialName = $UserName
Else
    If StringInStr($UserFullName, " ") Then
        $UserFullName_splited = StringSplit($UserFullName, " ")
        $UserPartialName = $UserFullName_splited[1]
    Else
        $UserPartialName = $UserName
    EndIf
EndIf

_FileWriteLog($LogFile, "====================================================================================")


;############################
;#  ROTINAS PRÉ-EXECUÇÃO #
;############################


;~ $StandAloneMode = 1
;~ $FullCmdLine = "C:\MATLAB\R2008b\bin\win32\MATLAB.exe"
;~ Global $MATLAB_GLOBAL_SETTINGS = "\\nfscad05.sjk.emb\dmuv5\applications\EngTools\CAE\Applications\MATLAB\MATLAB-GLOBAL-SETTINGS.INI"
;~ MsgBox(0,"$MyFlexLMDLL",$MyFlexLMDLL)
;~ $cmdlineraw = "/profile:011"
;~ If String($StandAloneMode) = String("0") Then

_FileWriteLog($LogFile, $UserName & " - " & @ComputerName & " - EngTools " & $AppName & " - Started - Normal")

;~ If $CMDLINE[0] = 0 Then
;~  MsgBox(262160, "ERROR: Matlab Starter ", "APPLICATION ERROR" & @CRLF & "Please call r.1087" & @CRLF & @CRLF & "Error Code: " & $CMDLINE[0])
;~  Exit
;~ EndIf
$FullCmdLine = "C:\Windows\system32\calc.exe"
;~ $FullCmdLine = "C:\MATLAB\R2008b\bin\win32\MATLAB.exe"
;~ $FullCmdLine = $CMDLINE[1]
$FullCmdLine_Splited = StringSplit($FullCmdLine, " ")
$Application = $FullCmdLine_Splited[1]

_FileWriteLog($LogFile, $UserName & " - " & @ComputerName & " - Comandline: " & $cmdlineraw)

If String($Debug) = String("1") Then
    _FileWriteLog($TraceFile, "$cmdlineraw: " & $cmdlineraw)
EndIf

If StringInStr($cmdlineraw, "/toolbox:(") Then
    $Toolboxes = StringTrimLeft($cmdlineraw, StringInStr($cmdlineraw, "/toolbox:(") + 9)
    $Toolboxes = StringLeft($Toolboxes, StringInStr($Toolboxes, ")") - 1)
EndIf

If StringInStr($cmdlineraw, "/MATLABparam:(") Then
    Global $MATLABparam = StringTrimLeft($cmdlineraw, StringInStr($cmdlineraw, "/MATLABparam:(") + 13)
    $MATLABparam = StringLeft($MATLABparam, StringInStr($MATLABparam, ")") - 1)
Else
    Global $MATLABparam = ""
EndIf

If StringInStr($cmdlineraw, "/profile:") Then
    $Profile = StringTrimLeft($cmdlineraw, StringInStr($cmdlineraw, "/profile:") + 8)
    $Profile = StringLeft($Profile, 3)
    $StandAloneMode = 2
    _RunMatlab($Profile, $Application)
EndIf

;###############################
;# TELA PRINCIPAL DA APLICAÇÃO #
;###############################

If String($Debug) = String("1") Then
    _FileWriteLog($TraceFile, "Criando tela . . . EngTools: " & $AppName & " - " & EnvGet("EngTools_Env") & " - " & EnvGet("MATLAB_USERNAME"))
EndIf

Global $Form_MATLAB_Profiles = GUICreate("EngTools: " & $AppName & " - " & EnvGet("EngTools_Env") & " - " & EnvGet("MATLAB_USERNAME"), 725, 713, -1, -1, BitOR($WS_SYSMENU, $WS_CAPTION, $WS_POPUP, $WS_POPUPWINDOW, $WS_BORDER, $WS_CLIPSIBLINGS), $WS_EX_APPWINDOW);, BitOR($WS_CAPTION,  $WS_CLIPSIBLINGS), $WS_EX_APPWINDOW)

#Region ## GRUPO WELCOME ##

$Group_Welcome = GUICtrlCreateGroup("", 0, 0, 721, 41);Grupo Welcome
$Label_WelcomeText = GUICtrlCreateLabel("Loading . . .", 3, 9, 715, 28, $SS_CENTER)
GUICtrlSetFont($Label_WelcomeText, 14, 800, 0, "MS Sans Serif")

GUICtrlSetData($Label_WelcomeText, "Good Morning - " & $UserPartialName)
GUICtrlSetColor($Label_WelcomeText, $Color_G)

If @HOUR > "11" Then
    GUICtrlSetData($Label_WelcomeText, "Good Afternoon - " & $UserPartialName)
    GUICtrlSetColor($Label_WelcomeText, $Color_B)
EndIf
If @HOUR > "18" Then
    GUICtrlSetData($Label_WelcomeText, "Good Evening - " & $UserPartialName)
EndIf
GUICtrlCreateGroup("", -99, -99, 1, 1);Fecha o grupo Welcome ($Group_Welcome)

#EndRegion ## GRUPO WELCOME ##

GUICtrlCreateGroup(" TOOLBOXES ", 0, 45, 721, 260);Grupo TOOLBOXES
Global $TreeView_Profiles = GUICtrlCreateListView("", 1, 58, 718, 245, -1, BitOR($LVS_EX_CHECKBOXES, $LVS_EX_GRIDLINES, $LVS_EX_FLATSB, $LVS_EX_SNAPTOGRID))
GUICtrlSetStyle($TreeView_Profiles, BitOR($LVS_LIST, $LVS_SHOWSELALWAYS)); set this ListView to LVS_ICON-style cause LVS_ICON = 0x0000
GUICtrlCreateGroup("", -99, -99, 1, 1);Fecha o grupo TOOLBOXES

$Button_CheckToolBox = GUICtrlCreateButton("Search Profile", 5, 310, 110, 40)
GUICtrlSetTip($Button_CheckToolBox, "Search for a available profile.")
$hImage_Button_CheckToolBox = _GUIImageList_Create(32, 32, 5, 3)
_GUIImageList_AddIcon($hImage_Button_CheckToolBox, $hImage_Search, 0, True)
_GUICtrlButton_SetImageList($Button_CheckToolBox, $hImage_Button_CheckToolBox)

$Button_ClearToolBox = GUICtrlCreateButton("Uncheck All", 135, 310, 110, 40)
GUICtrlSetTip(-1, "Search for a available profile.")
$hImage_Button_ClearToolBox = _GUIImageList_Create(32, 32, 5, 3)
_GUIImageList_AddIcon($hImage_Button_ClearToolBox, $hImage_Clear, 0, True)
_GUICtrlButton_SetImageList($Button_ClearToolBox, $hImage_Button_ClearToolBox)

$Button_Close = GUICtrlCreateButton("EXIT", 640, 310, 70, 40, $BS_MULTILINE)
$hImage_Button_Close = _GUIImageList_Create(32, 32, 5, 3)
_GUIImageList_AddIcon($hImage_Button_Close, $hImage_Exit, 0, True)
_GUICtrlButton_SetImageList($Button_Close, $hImage_Button_Close)

$Label_Wait = GUICtrlCreateLabel("Please Wait . . .", 260, 310, 245, 41)
GUICtrlSetFont($Label_Wait, 24, 800, 0, "MS Sans Serif")
GUICtrlSetColor($Label_Wait, 0xFF0000)
GUICtrlSetState($Label_Wait, $GUI_HIDE)

$ListView_Aval_Profiles = GUICtrlCreateListView("ID|% FREE|Nº TOOLBOXES", 0, 360, 250, 315, BitOR($LVS_NOLABELWRAP, $LVS_SINGLESEL, $LVS_SORTASCENDING, $TVS_CHECKBOXES), BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
_GUICtrlListView_JustifyColumn($ListView_Aval_Profiles, 0, 2)
_GUICtrlListView_JustifyColumn($ListView_Aval_Profiles, 1, 2)
_GUICtrlListView_JustifyColumn($ListView_Aval_Profiles, 2, 2)

;~ _GUICtrlListView_SetExtendedListViewStyle($ListView_Aval_Profiles, BitOR($LVS_EX_FLATSB, $LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_ONECLICKACTIVATE))


_GUICtrlListView_SetColumnWidth($ListView_Aval_Profiles, 0, $LVSCW_AUTOSIZE_USEHEADER)
_GUICtrlListView_SetColumnWidth($ListView_Aval_Profiles, 1, $LVSCW_AUTOSIZE_USEHEADER)
_GUICtrlListView_SetColumnWidth($ListView_Aval_Profiles, 2, $LVSCW_AUTOSIZE_USEHEADER)

$LabelRefresh = GUICtrlCreateLabel("There is no available profile containing all selected toolboxes.", 250, 310, 250, 40, $SS_CENTER)
GUICtrlSetColor($LabelRefresh, $Color_R)
GUICtrlSetFont($LabelRefresh, 10, 500)
GUICtrlSetState($LabelRefresh, $GUI_HIDE)

GUICtrlCreateGroup(" PROFILE TOOLBOX LIST ", 510, 355, 210, 315, $BS_CENTER);Grupo FEATURE TOOLBOX LIST
$ListToolBox = GUICtrlCreateList("", 519, 372, 194, 301, BitOR($LBS_NOSEL, $WS_VSCROLL, $LBS_SORT))
GUICtrlSetColor($ListToolBox, 0x9999)
GUICtrlCreateGroup("", -99, -99, 1, 1);Fecha o grupo FEATURE TOOLBOX LIST

GUICtrlCreateGroup(" OPTIONS ", 260, 355, 240, 210, $BS_CENTER);Grupo OPTIONS

$Button_RunMatlab = GUICtrlCreateButton("CHECKOUT PROFILE #", 320, 380, 110, 50, $BS_MULTILINE)
$hImage_Button_RunMatlab = _GUIImageList_Create(32, 32, 5, 3)
_GUIImageList_AddIcon($hImage_Button_RunMatlab, $hImage, 0, True)
_GUICtrlButton_SetImageList($Button_RunMatlab, $hImage_Button_RunMatlab)
GUICtrlSetState($Button_RunMatlab, $GUI_DISABLE)

$Button_CreateShortCut = GUICtrlCreateButton("Create Desktop Shortcut", 265, 440, 110, 50, $BS_MULTILINE)
$hImage_Button_CreateShortCut = _GUIImageList_Create(32, 32, 5, 3)
_GUIImageList_AddIcon($hImage_Button_CreateShortCut, $hImage_ShortCut, 0, True)
_GUICtrlButton_SetImageList($Button_CreateShortCut, $hImage_Button_CreateShortCut)
GUICtrlSetState($Button_CreateShortCut, $GUI_DISABLE)

$Button_GetCMDLine = GUICtrlCreateButton("Get Direct Command Line", 385, 440, 110, 50, $BS_MULTILINE)
$hImage_Button_GetCMDLine = _GUIImageList_Create(32, 32, 5, 3)
_GUIImageList_AddIcon($hImage_Button_GetCMDLine, $hImage_CMDLine, 0, True)
_GUICtrlButton_SetImageList($Button_GetCMDLine, $hImage_Button_GetCMDLine)
GUICtrlSetState($Button_GetCMDLine, $GUI_DISABLE)

$Button_Help = GUICtrlCreateButton("HELP", 320, 500, 110, 50, $BS_MULTILINE)
$hImage_Button_Help = _GUIImageList_Create(32, 32, 5, 3)
_GUIImageList_AddIcon($hImage_Button_Help, $hImage_Help, 0, True)
_GUICtrlButton_SetImageList($Button_Help, $hImage_Button_Help)

GUICtrlCreateGroup("", -99, -99, 1, 1);Fecha o grupo OPTIONS

GUICtrlCreateGroup("", 260, 675, 460, 35);Grupo ABOUT
$LabelDMUInfra = GUICtrlCreateLabel("Desenvolvido pelo Time de Desenv. e Gestão de Ambientes CAD/CAE - Versão: " & FileGetVersion(@AutoItExe), 265, 688, 450, 20, $SS_CENTER)
GUICtrlSetState($LabelDMUInfra, $GUI_DISABLE)
GUICtrlCreateGroup("", -99, -99, 1, 1);Fecha o grupo ABOUT

;~ $pic = GUICreate("", 130, 100, 310, 590, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $Form_MATLAB_Profiles)
;~ GUICtrlCreatePic($hImage_EMBLogo, 0, 0, 130, 100)

;Montagem da tela de profiles
$ProfilesSection = IniReadSection($MATLAB_GLOBAL_SETTINGS, "PROFILES")
Dim $ProfilesArray[300]


If $ProfilesSection[0][0] > 0 Then
    $i = 0

    $ProfileBuffer = ";SistemicUser_1;SistemicUser_2;SistemicUser_3;(...);"
    $CountProfiles = 0
    While 1
        $j = 1
        $Profile_Splited = StringSplit($ProfilesSection[$i][1], ";")
        While 1

            If Not StringInStr($ProfileBuffer, ";" & $Profile_Splited[$j] & ";") And $Profile_Splited[$j] <> "" Then
                $CountProfiles = $CountProfiles + 1
                $ProfileBuffer = $ProfileBuffer & $Profile_Splited[$j] & ";"
                $hText = StringUpper($Profile_Splited[$j])

                If $hText <> "" Then
                    _ArrayAdd($ProfilesArray, $hText)
                EndIf
            EndIf
            If $j = $Profile_Splited[0] Then ExitLoop
            $j = $j + 1
        WEnd
        If $i = $ProfilesSection[0][0] Then ExitLoop
        $i = $i + 1
    WEnd

    _ArraySort($ProfilesArray, 0)
    $ProfilesArray_String = _ArrayToString($ProfilesArray, "|")
    $ProfilesArray_String = StringReplace($ProfilesArray_String, "||", "")

    $ProfilesArray = StringSplit($ProfilesArray_String, "|")
    $CountProfiles = 1

    While 1
        If $ProfilesArray[$CountProfiles] <> "" Then
            $ProfileItem[$CountProfiles] = GUICtrlCreateListViewItem($ProfilesArray[$CountProfiles], $TreeView_Profiles)
            If StringInStr($Toolboxes, $ProfilesArray[$CountProfiles]) Or $ProfilesArray[$CountProfiles] = "MATLAB" Then
                GUICtrlSetState($ProfileItem[$CountProfiles], $GUI_CHECKED)
                GUICtrlSetBkColor($ProfileItem[$CountProfiles], $Color_G)
            Else
                GUICtrlSetState($ProfileItem[$CountProfiles], $GUI_UNCHECKED)
                GUICtrlSetBkColor($ProfileItem[$CountProfiles], 0xFFFFFF)
            EndIf
            GUICtrlSetImage($TreeView_Profiles, $hImage, 1)
        EndIf
        If $CountProfiles = $ProfilesArray[0] Then ExitLoop
        $CountProfiles = $CountProfiles + 1
    WEnd

EndIf

$SelectedCollum = ""
$CountTreeView_Profiles = 0


GUISetState(@SW_SHOW, $Form_MATLAB_Profiles)

If String($Debug) = String("1") Then
    _FileWriteLog($TraceFile, "Tela criada")
EndIf





Do

    $nMsg = GUIGetMsg(1)


    Switch $nMsg[0]

        Case $GUI_EVENT_PRIMARYUP
            If _GUICtrlListView_GetSelectedIndices($ListView_Aval_Profiles, False) <> $SelectedCollum Then

                $SelectedCollum = _GUICtrlListView_GetSelectedIndices($ListView_Aval_Profiles, False)

                If String($Debug) = String("1") Then
                    _FileWriteLog($TraceFile, "$SelectedCollum: " & $SelectedCollum)
                EndIf

                If $SelectedCollum <> "" And $SelectedCollum <> $SelectedCollum_Buffer Then
                    $SelectedCollum_Buffer = $SelectedCollum
                    $SelectedRow = _GUICtrlListView_GetItemText($ListView_Aval_Profiles, Number($SelectedCollum), 0)
                    If Number($SelectedRow) < Number(10) Then
                        $SelectedRow = String("00") & String($SelectedRow)
                    Else
                        $SelectedRow = String("0") & String($SelectedRow)
                    EndIf
                    $ProfilesList = IniRead($MATLAB_GLOBAL_SETTINGS, "PROFILES", $SelectedRow, "")
                    $ProfilesList_Split = StringSplit($ProfilesList, ";")
                    _GUICtrlListBox_ResetContent($ListToolBox)
                    If $ProfilesList_Split[0] > 0 Then
                        $CountProfiles_Splited = 1
                        While 1
                            GUICtrlSetData($ListToolBox, StringUpper($ProfilesList_Split[$CountProfiles_Splited]))
                            If $CountProfiles_Splited = $ProfilesList_Split[0] Then ExitLoop
                            $CountProfiles_Splited = $CountProfiles_Splited + 1
                        WEnd

                    EndIf
                    GUICtrlSetData($Button_RunMatlab, "CHECKOUT PROFILE #" & $SelectedRow)
                    _GUICtrlListBox_Sort($ListToolBox)
                    _GUICtrlListBox_Sort($ListToolBox)
                    _GUICtrlListView_ClickItem($ListView_Aval_Profiles, $SelectedCollum, "left", False, 1)

                EndIf
                If $SelectedRow = "" Then
                    GUICtrlSetState($Button_RunMatlab, $GUI_DISABLE)
                    GUICtrlSetData($Button_RunMatlab, "CHECKOUT PROFILE #")
                    GUICtrlSetState($Button_CreateShortCut, $GUI_DISABLE)
                    GUICtrlSetState($Button_GetCMDLine, $GUI_DISABLE)
                Else
                    GUICtrlSetState($Button_RunMatlab, $GUI_ENABLE)
                    GUICtrlSetState($Button_CreateShortCut, $GUI_ENABLE)
                    GUICtrlSetState($Button_GetCMDLine, $GUI_ENABLE)
                EndIf


            EndIf



        Case $Button_GetCMDLine
            GUICtrlSetState($LabelRefresh, $GUI_HIDE)
            If String($Debug) = String("1") Then
                _FileWriteLog($TraceFile, "$Button_GetCMDLine")
            EndIf
            If $SelectedRow <> "" Then
                $InputBox_Shortcut = InputBox("EngTools " & $AppName & " Command Line", "Press OK button to copy to clipboard", $EngToolsDir & "\EngTools.exe " & "/runCAE /programCAE:" & EnvGet("EngTools_Program") & " /envCAE:" & EnvGet("EngTools_Env") & " /cae /CAEParam:/profile:" & $SelectedRow)
                If $InputBox_Shortcut <> "" Then
                    ClipPut($InputBox_Shortcut)
                    _FileWriteLog($LogFile, $UserName & " - " & @ComputerName & " - Clipboard Copy: " & $InputBox_Shortcut)
                    MsgBox(262208, "EngTools " & $AppName & " Command Line", "The command line was copied to clipboard")
                EndIf
            EndIf

        Case $Button_CreateShortCut
            GUICtrlSetState($LabelRefresh, $GUI_HIDE)
            If String($Debug) = String("1") Then
                _FileWriteLog($TraceFile, "$Button_CreateShortCut")
            EndIf
            If $SelectedRow <> "" Then
                $InputBox_Shortcut = InputBox("EngTools Shortcut Name", "Type a EngTools Shortcut Name", "EngTools - " & $AppName & " " & EnvGet("EngTools_Env") & " Profile #" & $SelectedRow)
                GUICtrlSetState($Label_Wait, $GUI_SHOW)
                If $InputBox_Shortcut <> "" Then
                    $ShortCut = FileCreateShortcut($EngToolsDir & "\EngTools.exe", @DesktopDir & "\" & $InputBox_Shortcut, $EngToolsDir, "/runCAE /programCAE:" & EnvGet("EngTools_Program") & " /envCAE:" & EnvGet("EngTools_Env") & " /cae /CAEParam:/profile:" & $SelectedRow, $InputBox_Shortcut)
                    If $ShortCut = 1 Then
                        Sleep(1000)
                        If FileExists(@DesktopDir & "\" & $InputBox_Shortcut & "*") Then
                            GUICtrlSetState($Label_Wait, $GUI_HIDE)
                            _FileWriteLog($LogFile, $UserName & " - " & @ComputerName & " - Shortcut created: " & $InputBox_Shortcut)
                            MsgBox(262208, "Shortcut Created", "The shortcut was sucessfuly created")
                        EndIf
                    EndIf
                EndIf
            EndIf
            GUICtrlSetState($Label_Wait, $GUI_HIDE)

        Case $Button_Help
            If String($Debug) = String("1") Then
                _FileWriteLog($TraceFile, "$Button_Help")
            EndIf
            GUICtrlSetState($Label_Wait, $GUI_SHOW)
            ShellExecute(@ScriptDir & "\HELP.PDF")
            _FileWriteLog($LogFile, $UserName & " - " & @ComputerName & " - Help started")
            Sleep(2000)
            GUICtrlSetState($Label_Wait, $GUI_HIDE)

        Case $Button_RunMatlab
            GUICtrlSetState($LabelRefresh, $GUI_HIDE)
            If String($Debug) = String("1") Then
                _FileWriteLog($TraceFile, "$Button_RunMatlab")
            EndIf
            GUICtrlSetState($Label_Wait, $GUI_SHOW)
            GUICtrlSetState($Button_RunMatlab, $GUI_DISABLE)
            $Count = 0
            $Feature_Buffer = ""
            While 1
                If String(GUICtrlRead($ProfileItem[$Count], 1)) = String("1") Then
                    $Feature_Buffer = $Feature_Buffer & GUICtrlRead($ProfileItem[$Count]) & ";"
                EndIf
                If $Count = $CountProfiles Then ExitLoop
                $Count = $Count + 1
            WEnd
            IniWrite($LocalSettings, "Matlab", "ToolBoxes", $Feature_Buffer)

            If $SelectedRow <> "" Then
                _FileWriteLog($LogFile, $UserName & " - " & @ComputerName & " - " & $AppName & " Started - Profile: " & $SelectedRow & " - Application: " & $Application)
                _RunMatlab($SelectedRow, $Application)
            EndIf
            GUICtrlSetState($Label_Wait, $GUI_HIDE)

        Case $Button_ClearToolBox
            GUICtrlSetState($LabelRefresh, $GUI_HIDE)
            If String($Debug) = String("1") Then
                _FileWriteLog($TraceFile, "$Button_ClearToolBox")
            EndIf
            GUICtrlSetState($Label_Wait, $GUI_SHOW)
            $ProfileSearch = 0
            $SelectedCollum_Buffer = ""
            $SelectedCollum = ""
            $SelectedRow = ""
            GUICtrlSetState($Button_RunMatlab, $GUI_DISABLE)
            GUICtrlSetData($Button_RunMatlab, "CHECKOUT PROFILE #")
            GUICtrlSetState($Button_CreateShortCut, $GUI_DISABLE)
            GUICtrlSetState($Button_GetCMDLine, $GUI_DISABLE)
            _GUICtrlListBox_ResetContent($ListToolBox)
            _GUICtrlListView_DeleteAllItems($ListView_Aval_Profiles)

            $Count = 0
            While 1
                GUICtrlSetState($ProfileItem[$Count], $GUI_UNCHECKED)
                GUICtrlSetBkColor($ProfileItem[$Count], 0xFFFFFF)
                If $Count = $CountProfiles Then ExitLoop
                $Count = $Count + 1
            WEnd
            GUICtrlSetState($Label_Wait, $GUI_HIDE)


        Case $Button_CheckToolBox
            GUICtrlSetState($LabelRefresh, $GUI_HIDE)
            If String($Debug) = String("1") Then
                _FileWriteLog($TraceFile, "$Button_CheckToolBox")
            EndIf
            GUICtrlSetState($Label_Wait, $GUI_SHOW)
            $ProfileSearch = 0
            $SelectedCollum_Buffer = ""
            $SelectedCollum = ""
            _CheckToolBoxButton()
            $SelectedCollum_Buffer = ""
            $SelectedCollum = ""
            GUICtrlSetState($Label_Wait, $GUI_HIDE)

        Case $GUI_EVENT_CLOSE
            If String($Debug) = String("1") Then
                _FileWriteLog($TraceFile, "$GUI_EVENT_CLOSE")
            EndIf
            Exit
        Case $Button_Close
            If String($Debug) = String("1") Then
                _FileWriteLog($TraceFile, "$Button_Close")
            EndIf
            Exit

    EndSwitch
    
    
Until $nMsg[0] = $GUI_EVENT_CLOSE



Func _CheckToolBoxButton()
    If String($Debug) = String("1") Then
        _FileWriteLog($TraceFile, "Entrei no modo de verificação do Toolbox")
    EndIf
    If String($Debug) = String("1") Then
        _FileWriteLog($TraceFile, "_CheckToolBoxButton()")
    EndIf
    $Timer_Refresh = TimerInit()
    _GUICtrlListBox_ResetContent($ListToolBox)
    _GUICtrlListView_DeleteAllItems($ListView_Aval_Profiles)
    $Count = 0
    $Feature_Buffer = ""
    While 1
        If String(GUICtrlRead($ProfileItem[$Count], 1)) = String("1") Then
            $Feature_Buffer = $Feature_Buffer & GUICtrlRead($ProfileItem[$Count]) & "|"
            GUICtrlSetBkColor($ProfileItem[$Count], $Color_G)
        Else
            GUICtrlSetBkColor($ProfileItem[$Count], 0xFFFFFF)
            GUICtrlSetState($ProfileItem[$Count], $GUI_NOFOCUS)
        EndIf
        If $Count = $CountProfiles Then ExitLoop
        $Count = $Count + 1
    WEnd

    IniWrite($LocalSettings, "Matlab", "ToolBoxes", StringReplace($Feature_Buffer, "|", ";"))

    $Count_Name = 1
    $Profile_Name = ""
    While 1
        If $ProfilesSection[$Count_Name][0] <> "#ProfileID" Then
            $Profile_Name = $Profile_Name & $ProfilesSection[$Count_Name][0] & "|"
        EndIf
        If $Count_Name = $ProfilesSection[0][0] Then ExitLoop
        $Count_Name = $Count_Name + 1
    WEnd
    $Profile_Name = StringTrimRight($Profile_Name, 1)
    $Feature_Buffer = StringTrimRight($Feature_Buffer, 1);Guarda o nome das Features que foram selecionadas
    $Feature_Buffer_Splited = StringSplit($Feature_Buffer, "|")
    If $Feature_Buffer_Splited[0] > 0 Then
        $Count_Profile = 1
        While 1
            $ProfileSplit = StringSplit($Profile_Name, "|")
            If $ProfileSplit[0] > 0 Then
                $Count_Name = 1
                $Profile_Name = ""
                While 1
                    $ProfileINIContent = IniRead($MATLAB_GLOBAL_SETTINGS, "PROFILES", $ProfileSplit[$Count_Name], "")
                    If StringInStr($ProfileINIContent, $Feature_Buffer_Splited[$Count_Profile]) Then
                        $Profile_Name = $Profile_Name & $ProfileSplit[$Count_Name] & "|"
                    EndIf
                    If $Count_Name = $ProfileSplit[0] Then ExitLoop
                    $Count_Name = $Count_Name + 1
                WEnd
            EndIf
            If $Count_Profile = $Feature_Buffer_Splited[0] Then ExitLoop
            $Count_Profile = $Count_Profile + 1
        WEnd
    EndIf

    If $Profile_Name <> "" Then
        $ProfileSearch = 1;Habilita o auto-refresh
        $Profile_Name = StringTrimRight($Profile_Name, 1)
        $Profile_Name_Splited = StringSplit($Profile_Name, "|")
        If $Profile_Name_Splited[0] > 0 Then
            $Count_Name = 1
            While 1
                $ProfileToolboxes = IniRead($MATLAB_GLOBAL_SETTINGS, "PROFILES", $Profile_Name_Splited[$Count_Name], "")
                $ProfileToolboxes_Count = StringSplit($ProfileToolboxes, ";")
                $Profile_SistemicUsers = IniRead($MATLAB_GLOBAL_SETTINGS, "SISTEMIC_USERS", $Profile_Name_Splited[$Count_Name], "")
                $Profile_SistemicUsers_TotalCount = StringSplit($Profile_SistemicUsers, ";")
                $Profile_SistemicUsers_Buffer = ""
                If $Profile_SistemicUsers_TotalCount[0] > 0 Then;Verifica o a quantidade de usuários sistemicos da feature estão em uso
                    $Count_SistemicUsers = 1
                    While 1
                        If Not FileExists($LockDirectory & "\" & $Profile_SistemicUsers_TotalCount[$Count_SistemicUsers] & ".ini") Then
                            $Profile_SistemicUsers_Buffer = $Profile_SistemicUsers_Buffer & $Profile_SistemicUsers_TotalCount[$Count_SistemicUsers] & "|"
                        EndIf
                        If $Count_SistemicUsers = $Profile_SistemicUsers_TotalCount[0] Then ExitLoop
                        $Count_SistemicUsers = $Count_SistemicUsers + 1
                    WEnd
                EndIf

                $Profile_SistemicUsers_Buffer = StringTrimRight($Profile_SistemicUsers_Buffer, 1)
                $Profile_SistemicUsers_FreeCount = StringSplit($Profile_SistemicUsers_Buffer, "|")
                If Not StringInStr($Profile_SistemicUsers_Buffer, "eng") Then
                    $Profile_SistemicUsers_FreeCount[0] = 0
                EndIf
                $InUsePercent = 100 - (100 * ($Profile_SistemicUsers_TotalCount[0] - $Profile_SistemicUsers_FreeCount[0])) / $Profile_SistemicUsers_TotalCount[0]
                $ListView_Checkout_[$Count_Name] = GUICtrlCreateListViewItem($Profile_Name_Splited[$Count_Name] & "|" & Round($InUsePercent, 1) & "%|" & $ProfileToolboxes_Count[0], $ListView_Aval_Profiles)
                If $Count_Name = $Profile_Name_Splited[0] Then ExitLoop
                $Count_Name = $Count_Name + 1
            WEnd
            $ListView_Checkout_[0] = $Count_Name
            $B_DESCENDING = False
            _GUICtrlListView_SimpleSort($ListView_Aval_Profiles, $B_DESCENDING, 2)
            $Count_Name = 0

            While 1
                $ItemText = _GUICtrlListView_GetItemText($ListView_Aval_Profiles, $Count_Name, 1)
                $ItemText = StringTrimRight($ItemText, 1)
                If Number($ItemText) > Number(50) Then
                    GUICtrlSetBkColor($ListView_Checkout_[$Count_Name + 1], $Color_G)
                Else
                    GUICtrlSetBkColor($ListView_Checkout_[$Count_Name + 1], $Color_Y)
                EndIf
                If Number($ItemText) = Number(0) Then
                    GUICtrlSetBkColor($ListView_Checkout_[$Count_Name + 1], $Color_R)
                EndIf
                If $Count_Name = $ListView_Checkout_[0] Then ExitLoop
                $Count_Name = $Count_Name + 1
            WEnd
            $Profile_Name = ""
        Else
            GUICtrlSetState($LabelRefresh, $GUI_SHOW)
        EndIf
    Else
        GUICtrlSetState($LabelRefresh, $GUI_SHOW)
    EndIf
    _GUICtrlListView_SetItemState($ListView_Aval_Profiles, 0, $LVIS_FOCUSED, $LVIS_FOCUSED)
    _GUICtrlListView_SetItemState($ListView_Aval_Profiles, 0, $LVIS_SELECTED, $LVIS_SELECTED)



EndFunc  ;==>_CheckToolBoxButton



Func _RunMatlab($ProfileInUse, $RunCommand)
    If String($Debug) = String("1") Then
        _FileWriteLog($TraceFile, "Entrei no modo de execução do matlab")
    EndIf
    If String($Debug) = String("1") Then
        _FileWriteLog($TraceFile, "_RunMatlab( " & $ProfileInUse & ", " & $RunCommand & " )")
    EndIf
;~  MsgBox(0,"","entrei1")
    $Profile_SistemicUsers = IniRead($MATLAB_GLOBAL_SETTINGS, "SISTEMIC_USERS", $ProfileInUse, "")
    $Profile_SistemicUsers_TotalCount = StringSplit($Profile_SistemicUsers, ";")
    $Profile_SistemicUsers_Buffer = ""
    If $Profile_SistemicUsers_TotalCount[0] > 0 Then
        $Count_SistemicUsers = 1
        While 1
            If Not FileExists($LockDirectory & "\" & $Profile_SistemicUsers_TotalCount[$Count_SistemicUsers] & ".ini") Then

                $SistemicUser_CheckOut = $Profile_SistemicUsers_TotalCount[$Count_SistemicUsers]
                $SistemicUserData = _UserPasswd($SistemicUser_CheckOut)
                $SistemicUserDataSplit = StringSplit($SistemicUserData, "|")
                Local $MyTrash
                Local $result = DllCall($MyFlexLMDLL, "int", "_lmcheckout@20", "str", $MyFlexLMServer, "str", $MyFlexLMVersion, "str", $SistemicUserDataSplit[3], "str", $MyTrash, "str", $MyTrash)
                If $result[4] = $Profile_SistemicUsers_TotalCount[$Count_SistemicUsers] Then
                    #cs
                        If String($StandAloneMode) = String("1") Then
                        $RunCommand = StringReplace($RunCommand, "matlab.exe", "matlab_original.exe")
                        ConsoleWrite($RunCommand & @CRLF)
                        EndIf
                    #ce
                    If FileExists($RunCommand) Then
                        IniWrite($LockDirectory & "\" & $Profile_SistemicUsers_TotalCount[$Count_SistemicUsers] & ".ini", "CHECKOUT", "USER", EnvGet("MATLAB_USERNAME"))

                        If $MATLABparam <> "" Then
                            $MATLABparam = " " & $MATLABparam
                        EndIf

                        If $RunPath = "" Then
                            $RunPath = "c:\"
                        EndIf

                        #cs
                            If String($StandAloneMode) = String("1") Then
                            $LogFile_Local = StringReplace($RunCommand, "matlab_original.exe", "EngTools.log")
                            _FileWriteLog($LogFile_Local, $UserName & " - " & @ComputerName & " - RunCommnad: " & $RunCommand & $MATLABparam)
                            _FileWriteLog($LogFile_Local, $UserName & " - " & @ComputerName & " - RunPath: " & $RunPath)
                            EndIf
                        #ce

                        $PID = RunAs($SistemicUserDataSplit[2], "EMBAD", $SistemicUserDataSplit[1], 1, $RunCommand & $MATLABparam, $RunPath, @SW_MAXIMIZE)

                        ProcessWait($PID, 15)
                        If ProcessExists($PID) Then
                            _ProcessMon($PID, $Profile_SistemicUsers_TotalCount[$Count_SistemicUsers], $ProfileInUse)
                        Else
                            GUICtrlSetState($Label_Wait, $GUI_HIDE)
                            _FileWriteLog($LogFile, $UserName & " - " & @ComputerName & " - Matlab Started - Fail: Process not found")
                            MsgBox(262160, ".: ERROR: " & $AppName & " Starter :.", "ERROR STARTING " & $AppName & ", please call r.1087" & @CRLF & "" & @CRLF & "Process is not starting !!!")
                            Exit
                        EndIf
                    Else
                        GUICtrlSetState($Label_Wait, $GUI_HIDE)
                        _FileWriteLog($LogFile, $UserName & " - " & @ComputerName & " - Matlab Started - Fail: File not found: " & $RunCommand)
                        MsgBox(262160, ".: ERROR: " & $AppName & " Starter :.", "ERROR STARTING " & $AppName & ", please call r.1087" & @CRLF & "" & @CRLF & "File not Found: " & $RunCommand)
                        Exit
                    EndIf
                Else
;~                  MsgBox(262160, ".: ERROR :.", "ERROR: Cannot checkout EMBRAER-MATLAB License..." & @CRLF & "Press 'OK' to try again . . .", 2)
                    IniWrite($LockDirectory & "\" & $Profile_SistemicUsers_TotalCount[$Count_SistemicUsers] & ".ini", "CHECKOUT", "USER", "*locked*")
                    If String($StandAloneMode) = String("0") Then
                        GUICtrlSetState($Button_RunMatlab, $GUI_ENABLE)
                    EndIf
                EndIf

            EndIf
            If $Count_SistemicUsers = $Profile_SistemicUsers_TotalCount[0] Then ExitLoop
            $Count_SistemicUsers = $Count_SistemicUsers + 1
        WEnd
        If String($StandAloneMode) = String("0") Then
            GUICtrlSetState($Label_Wait, $GUI_HIDE)
        EndIf
        _FileWriteLog($LogFile, $UserName & " - " & @ComputerName & " - " & $AppName & " Started - Fail: PROFILE #" & $ProfileInUse & " is Full !!!")
        MsgBox(262160, ".: ERROR - EngTools " & $AppName & " Starter:.", "PROFILE #" & $ProfileInUse & " is Full !!!")

        If String($StandAloneMode) = String("1") Or String($StandAloneMode) = String("2") Then
            Exit
        Else
            GUICtrlSetState($Button_RunMatlab, $GUI_ENABLE)
            $SelectedCollum_Buffer = ""
            $SelectedCollum = ""
            GUICtrlSetState($Label_Wait, $GUI_SHOW)
            _CheckToolBoxButton()
            GUICtrlSetState($Label_Wait, $GUI_HIDE)
            $SelectedCollum_Buffer = ""
            $SelectedCollum = ""
        EndIf
    EndIf

EndFunc  ;==>_RunMatlab



Func _ProcessMon($PID, $SistemicUser_Monitor, $FeatureID)
    If String($Debug) = String("1") Then
        _FileWriteLog($TraceFile, "Entrei no modo de monitoramento de processo")
    EndIf
    If String($StandAloneMode) <> String("1") And String($StandAloneMode) <> String("2") Then
        GUISetState(@SW_HIDE, $Form_MATLAB_Profiles)
        GUISetState(@SW_HIDE, $pic)
    EndIf
    _FileWriteLog($LogFile, $UserName & " - " & @ComputerName & " - " & $AppName & " Started - Success: Feature ID#" & $FeatureID & " - User Key: " & $SistemicUser_Monitor)
    TrayTip("Starting " & $AppName, "Feature ID#" & $FeatureID & @CRLF & "User Key: " & $SistemicUser_Monitor, 30, 1)
    Sleep(1000)
    $begin = TimerInit()

    $Kill = TrayCreateItem("&Close " & $AppName)
    TraySetToolTip("Feature ID#" & $FeatureID & @CRLF & "User Key: " & $SistemicUser_Monitor)
    TraySetState()
    If Not IsDeclared("iMsgBoxAnswer") Then Dim $iMsgBoxAnswer
    While 1
        $ProcMsg = TrayGetMsg()

        If $ProcMsg = $Kill Then

            $iMsgBoxAnswer = MsgBox(262436, "Close " & $AppName, "Are you sure do you want to close " & $AppName & "?" & @CRLF & @CRLF & "## ATENTION ##" & @CRLF & @CRLF & "All the not saved documents will be lost.")
            Select
                Case $iMsgBoxAnswer = 6;Yes
                    ProcessClose($PID)
                    Sleep(500)
                    If IniRead($LockDirectory & "\" & $SistemicUser_Monitor & ".ini", "CHECKOUT", "USER", "") = EnvGet("MATLAB_USERNAME") Then
                        FileDelete($LockDirectory & "\" & $SistemicUser_Monitor & ".ini")
                    EndIf
                    _FileWriteLog($LogFile, $UserName & " - " & @ComputerName & " - Process closed - Forced")
                    Exit
            EndSelect

        EndIf

        If TimerDiff($begin) > 1500 Then
            If Not ProcessExists($PID) Then
                Sleep(1000)
                If IniRead($LockDirectory & "\" & $SistemicUser_Monitor & ".ini", "CHECKOUT", "USER", "") = EnvGet("MATLAB_USERNAME") Then
                    FileDelete($LockDirectory & "\" & $SistemicUser_Monitor & ".ini")
                EndIf
                _FileWriteLog($LogFile, $UserName & " - " & @ComputerName & " - Process closed - Normal")
                Exit
            EndIf
            $begin = TimerInit()
        EndIf
    WEnd

EndFunc  ;==>_ProcessMon


Func _UserPasswd($SistemicUser)

    Return $SistemicUser

EndFunc  ;==>_UserPasswd

-----------------------------------------------------------------To a lot of people, the Sky is the limit. To person who love the aviation, the sky is the your own home.

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...