Jump to content

Is it possible to do this?


Go to solution Solved by Parsix,

Recommended Posts

what's up guys, I have a question as you know I'm still a newbie in AutoIT and I come from AMS (Autoplay Media Studio) is that I want to do the following that you see in the image try to make a text that can add certain things to it .. but the point I can't find a way to click on the button to make all the text change or appear as I want, but it looks like this:


"Sc Config a start=disabled
b"

and I would like it to be as you see in the image
they help me?

excuse me please my english is not very good, I'm using a translator

converter.png

Edited by TesterMachine
Link to post
Share on other sites
  • Solution
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiRichEdit.au3>

Opt("GUIOnEventMode", 1)

_Gui()



Func _Gui()
    Global $ConvertService =    GUICreate("ConvertService", 714, 416, 192, 124)
                                GUISetOnEvent($GUI_EVENT_CLOSE, "_onChange")
                                GUISetOnEvent($GUI_EVENT_MINIMIZE, "_onChange")

    Local $lbl_title        =   GUICtrlCreateLabel("Convert Service Name and CommandLine", 144, 24, 291, 20)
                                GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
                                GUICtrlSetColor(-1, 0x0078D7)


    Local $lbl_Service      =   GUICtrlCreateLabel("Services :", 73, 65, 73, 20)
                                GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
                                GUICtrlSetColor(-1, 0x0078D7)

    Global $edt_Service     =   _GUICtrlRichEdit_Create($ConvertService, "", 16, 91, 201, 297, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
                                _GUICtrlRichEdit_SetFont($edt_Service, 8, "MS Sans Serif")

    Global $btn_convert     =   GUICtrlCreateButton("Convert", 240, 192, 100, 25)
                                GUICtrlSetOnEvent(-1, "_onChange")
                                GUICtrlSetFont(-1, 10, 800, 0)

    Local $lbl_ScConfigs    =   GUICtrlCreateLabel("Sc Configs : ", 239, 227, 90, 20)
                                GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
                                GUICtrlSetColor(-1, 0x0078D7)

    Global $chb_Stop        =   GUICtrlCreateCheckbox("Stop", 240, 256, 97, 17)

    Global $chb_Start       =   GUICtrlCreateCheckbox("Start", 240, 280, 97, 17)

    Global $chb_Config      =   GUICtrlCreateCheckbox("Config", 240, 304, 97, 17)

    Global $cmb_config      =   GUICtrlCreateCombo("", 240, 328, 100, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
                                GUICtrlSetData(-1, "boot|system|auto|demand|disabled|delayed-auto")

    Global $btn_clear       =   GUICtrlCreateButton("Clear", 240, 328 + 25 + 7, 100, 25)
                                GUICtrlSetOnEvent(-1, "_onChange")


    Local $lbl_Converted    =   GUICtrlCreateLabel("Converted :", 446, 67, 83, 20)
                                GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
                                GUICtrlSetColor(-1, 0x0078D7)

    Global $edt_Converted   =   _GUICtrlRichEdit_Create($ConvertService, "", 382, 91, 313, 297, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL, $ES_READONLY ))
                                GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")

    _WinAPI_SetFocus($edt_Service)
    GUISetState(@SW_SHOW, $ConvertService)

    While 1
        Sleep(100)
    WEnd
EndFunc



Func _onChange()
    Switch @GUI_CtrlId
        Case $GUI_EVENT_CLOSE
            _GUICtrlRichEdit_Destroy($edt_Service)
            _GUICtrlRichEdit_Destroy($edt_Converted)
            GUIDelete($ConvertService)
            Exit
        Case $btn_clear
            _GUICtrlRichEdit_SetSel($edt_Service, 0, -1, True)    ; select all, but hide
            _GUICtrlRichEdit_ReplaceText($edt_Service, "")      ; replace all
            _GUICtrlRichEdit_SetSel($edt_Service, 0, 0)           ; set cursor to start

            _GUICtrlRichEdit_SetSel($edt_Converted, 0, -1, True)    ; select all, but hide
            _GUICtrlRichEdit_ReplaceText($edt_Converted, "")        ; replace all
            _GUICtrlRichEdit_SetSel($edt_Converted, 0, 0)           ; set cursor to start
        Case $btn_convert
            _GUICtrlRichEdit_SetSel($edt_Converted, 0, -1, True)    ; select all, but hide
            _GUICtrlRichEdit_ReplaceText($edt_Converted, "")        ; replace all
            _GUICtrlRichEdit_SetSel($edt_Converted, 0, 0)           ; set cursor to start

            Local $iAll_Lines = _GUICtrlRichEdit_GetLineCount ( $edt_Service )
            Local $sConverted = ""
            Local $sText = ""
            For $iLine = 1 To  $iAll_Lines

                $sText = _GUICtrlRichEdit_GetTextInLine ( $edt_Service, $iLine )

                If $sText<>"" Then

                    If _IsChecked($chb_Stop) Then
                        $sConverted = _create_commandline($sText, "stop")
                        If $sConverted Then _GUICtrlRichEdit_AppendText ( $edt_Converted,  $sConverted & @LF )
                    EndIf

                    If _IsChecked($chb_Start) Then
                        $sConverted = _create_commandline($sText, "start")
                        If $sConverted Then _GUICtrlRichEdit_AppendText ( $edt_Converted, $sConverted & @LF )
                    EndIf

                    If _IsChecked($chb_Config) Then
                        Local $sSC_config = GUICtrlRead($cmb_config)
                        If $sSC_config = "" Then $sSC_config = Default
                        $sConverted = _create_commandline($sText, "config", $sSC_config)
                        If $sConverted Then _GUICtrlRichEdit_AppendText  ( $edt_Converted, $sConverted & @LF )
                    EndIf

                EndIf

            Next
    EndSwitch
EndFunc




Func _IsChecked($idControlID)
    Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_CHECKED
EndFunc   ;==>_IsChecked


Func _create_commandline($serviceName, $sSc_SW, $sSc_config_SW = Default)
    Local $sOutput = ""
    Local $oError = False
    Switch $sSc_SW
        Case "stop"
            $sOutput = "sc stop " & '"' & $serviceName & '"'
        Case "start"
            $sOutput = "sc start " & '"' & $serviceName & '"'
        Case "config"
            ;<boot|system|auto|demand|disabled|delayed-auto>
            Switch $sSc_config_SW
                Case 1, "boot"
                    $sOutput = "sc config " & '"' & $serviceName & '"' & " start= " & "boot"
                Case 2, "system"
                    $sOutput = "sc config " & '"' & $serviceName & '"' & " start= " & "system"
                Case 3, "auto", Default
                    $sOutput = "sc config " & '"' & $serviceName & '"' & " start= " & "auto"
                Case 4, "demand"
                    $sOutput = "sc config " & '"' & $serviceName & '"' & " start= " & "demand"
                Case 5, "disabled"
                    $sOutput = "sc config " & '"' & $serviceName & '"' & " start= " & "disabled"
                Case 6, "delayed-aut"
                    $sOutput = "sc config " & '"' & $serviceName & '"' & " start= " & "delayed-aut"
            EndSwitch
    EndSwitch
    If $sOutput Then Return $sOutput
    Return $oError
EndFunc

 

Edited by Parsix
Link to post
Share on other sites
6 hours ago, Parsix said:
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiRichEdit.au3>

Opt("GUIOnEventMode", 1)

_Gui()



Func _Gui()
    Global $ConvertService =    GUICreate("ConvertService", 714, 416, 192, 124)
                                GUISetOnEvent($GUI_EVENT_CLOSE, "_onChange")
                                GUISetOnEvent($GUI_EVENT_MINIMIZE, "_onChange")

    Local $lbl_title        =   GUICtrlCreateLabel("Convert Service Name and CommandLine", 144, 24, 291, 20)
                                GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
                                GUICtrlSetColor(-1, 0x0078D7)


    Local $lbl_Service      =   GUICtrlCreateLabel("Services :", 73, 65, 73, 20)
                                GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
                                GUICtrlSetColor(-1, 0x0078D7)

    Global $edt_Service     =   _GUICtrlRichEdit_Create($ConvertService, "", 16, 91, 201, 297, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
                                _GUICtrlRichEdit_SetFont($edt_Service, 8, "MS Sans Serif")

    Global $btn_convert     =   GUICtrlCreateButton("Convert", 240, 192, 100, 25)
                                GUICtrlSetOnEvent(-1, "_onChange")
                                GUICtrlSetFont(-1, 10, 800, 0)

    Local $lbl_ScConfigs    =   GUICtrlCreateLabel("Sc Configs : ", 239, 227, 90, 20)
                                GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
                                GUICtrlSetColor(-1, 0x0078D7)

    Global $chb_Stop        =   GUICtrlCreateCheckbox("Stop", 240, 256, 97, 17)

    Global $chb_Start       =   GUICtrlCreateCheckbox("Start", 240, 280, 97, 17)

    Global $chb_Config      =   GUICtrlCreateCheckbox("Config", 240, 304, 97, 17)

    Global $cmb_config      =   GUICtrlCreateCombo("", 240, 328, 100, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
                                GUICtrlSetData(-1, "boot|system|auto|demand|disabled|delayed-auto")

    Global $btn_clear       =   GUICtrlCreateButton("Clear", 240, 328 + 25 + 7, 100, 25)
                                GUICtrlSetOnEvent(-1, "_onChange")


    Local $lbl_Converted    =   GUICtrlCreateLabel("Converted :", 446, 67, 83, 20)
                                GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
                                GUICtrlSetColor(-1, 0x0078D7)

    Global $edt_Converted   =   _GUICtrlRichEdit_Create($ConvertService, "", 382, 91, 313, 297, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL, $ES_READONLY ))
                                GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")

    _WinAPI_SetFocus($edt_Service)
    GUISetState(@SW_SHOW, $ConvertService)

    While 1
        Sleep(100)
    WEnd
EndFunc



Func _onChange()
    Switch @GUI_CtrlId
        Case $GUI_EVENT_CLOSE
            _GUICtrlRichEdit_Destroy($edt_Service)
            _GUICtrlRichEdit_Destroy($edt_Converted)
            GUIDelete($ConvertService)
            Exit
        Case $btn_clear
            _GUICtrlRichEdit_SetSel($edt_Service, 0, -1, True)    ; select all, but hide
            _GUICtrlRichEdit_ReplaceText($edt_Service, "")      ; replace all
            _GUICtrlRichEdit_SetSel($edt_Service, 0, 0)           ; set cursor to start

            _GUICtrlRichEdit_SetSel($edt_Converted, 0, -1, True)    ; select all, but hide
            _GUICtrlRichEdit_ReplaceText($edt_Converted, "")        ; replace all
            _GUICtrlRichEdit_SetSel($edt_Converted, 0, 0)           ; set cursor to start
        Case $btn_convert
            _GUICtrlRichEdit_SetSel($edt_Converted, 0, -1, True)    ; select all, but hide
            _GUICtrlRichEdit_ReplaceText($edt_Converted, "")        ; replace all
            _GUICtrlRichEdit_SetSel($edt_Converted, 0, 0)           ; set cursor to start

            Local $iAll_Lines = _GUICtrlRichEdit_GetLineCount ( $edt_Service )
            Local $sConverted = ""
            Local $sText = ""
            For $iLine = 1 To  $iAll_Lines

                $sText = _GUICtrlRichEdit_GetTextInLine ( $edt_Service, $iLine )

                If $sText<>"" Then

                    If _IsChecked($chb_Stop) Then
                        $sConverted = _create_commandline($sText, "stop")
                        If $sConverted Then _GUICtrlRichEdit_AppendText ( $edt_Converted,  $sConverted & @LF )
                    EndIf

                    If _IsChecked($chb_Start) Then
                        $sConverted = _create_commandline($sText, "start")
                        If $sConverted Then _GUICtrlRichEdit_AppendText ( $edt_Converted, $sConverted & @LF )
                    EndIf

                    If _IsChecked($chb_Config) Then
                        Local $sSC_config = GUICtrlRead($cmb_config)
                        If $sSC_config = "" Then $sSC_config = Default
                        $sConverted = _create_commandline($sText, "config", $sSC_config)
                        If $sConverted Then _GUICtrlRichEdit_AppendText  ( $edt_Converted, $sConverted & @LF )
                    EndIf

                EndIf

            Next
    EndSwitch
EndFunc




Func _IsChecked($idControlID)
    Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_CHECKED
EndFunc   ;==>_IsChecked


Func _create_commandline($serviceName, $sSc_SW, $sSc_config_SW = Default)
    Local $sOutput = ""
    Local $oError = False
    Switch $sSc_SW
        Case "stop"
            $sOutput = "sc stop " & '"' & $serviceName & '"'
        Case "start"
            $sOutput = "sc start " & '"' & $serviceName & '"'
        Case "config"
            ;<boot|system|auto|demand|disabled|delayed-auto>
            Switch $sSc_config_SW
                Case 1, "boot"
                    $sOutput = "sc config " & '"' & $serviceName & '"' & " start= " & "boot"
                Case 2, "system"
                    $sOutput = "sc config " & '"' & $serviceName & '"' & " start= " & "system"
                Case 3, "auto", Default
                    $sOutput = "sc config " & '"' & $serviceName & '"' & " start= " & "auto"
                Case 4, "demand"
                    $sOutput = "sc config " & '"' & $serviceName & '"' & " start= " & "demand"
                Case 5, "disabled"
                    $sOutput = "sc config " & '"' & $serviceName & '"' & " start= " & "disabled"
                Case 6, "delayed-aut"
                    $sOutput = "sc config " & '"' & $serviceName & '"' & " start= " & "delayed-aut"
            EndSwitch
    EndSwitch
    If $sOutput Then Return $sOutput
    Return $oError
EndFunc

 

wow thank you very much it was just what I was looking for, I never thought I would have to use the GUIOnEventMode, well thank you for your help :) honestly I had no idea how to do it

Link to post
Share on other sites
3 hours ago, TesterMachine said:

wow thank you very much it was just what I was looking for, I never thought I would have to use the GUIOnEventMode, well thank you for your help :) honestly I had no idea how to do it

 

Without GUIOnEventMode 

The order of execution of the commands was added

 

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiRichEdit.au3>


_Gui()



Func _Gui()
    Local $ConvertService   =   GUICreate("ConvertService", 714, 416, 192, 124)

    Local $lbl_title        =   GUICtrlCreateLabel("Convert Service Name and CommandLine", 144, 24, 291, 20)
                                GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
                                GUICtrlSetColor(-1, 0x0078D7)


    Local $lbl_Service      =   GUICtrlCreateLabel("Services :", 73, 65, 73, 20)
                                GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
                                GUICtrlSetColor(-1, 0x0078D7)

    Local $edt_Service      =   _GUICtrlRichEdit_Create($ConvertService, "", 16, 91, 201, 297, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
                                _GUICtrlRichEdit_SetFont($edt_Service, 8, "MS Sans Serif")

    Local $btn_convert      =   GUICtrlCreateButton("Convert", 240, 192, 100, 25)
                                GUICtrlSetFont(-1, 10, 800, 0)

    Local $lbl_ScConfigs    =   GUICtrlCreateLabel("Sc Configs : ", 239, 227, 90, 20)
                                GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
                                GUICtrlSetColor(-1, 0x0078D7)

    Local $chb_Stop         =   GUICtrlCreateCheckbox("Stop", 240, 256, 97, 17)

    Local $chb_Start        =   GUICtrlCreateCheckbox("Start", 240, 280, 97, 17)

    Local $chb_Config       =   GUICtrlCreateCheckbox("Config", 240, 304, 97, 17)

    Local $cmb_config       =   GUICtrlCreateCombo("", 240, 328, 100, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
                                GUICtrlSetData(-1, "boot|system|auto|demand|disabled|delayed-auto")

    Local $btn_clear        =   GUICtrlCreateButton("Clear", 240, 328 + 25 + 7, 100, 25)

    Local $lbl_Converted    =   GUICtrlCreateLabel("Converted :", 446, 67, 83, 20)
                                GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
                                GUICtrlSetColor(-1, 0x0078D7)

    Local $edt_Converted    =   _GUICtrlRichEdit_Create($ConvertService, "", 382, 91, 313, 297, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL, $ES_READONLY ))
                                GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")

    _WinAPI_SetFocus($edt_Service)
    GUISetState(@SW_SHOW, $ConvertService)

    While 1
        ;Sleep(100)
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $btn_clear
                _GUICtrlRichEdit_SetSel($edt_Service, 0, -1, True)    ; select all, but hide
                _GUICtrlRichEdit_ReplaceText($edt_Service, "")      ; replace all
                _GUICtrlRichEdit_SetSel($edt_Service, 0, 0)           ; set cursor to start

                _GUICtrlRichEdit_SetSel($edt_Converted, 0, -1, True)    ; select all, but hide
                _GUICtrlRichEdit_ReplaceText($edt_Converted, "")        ; replace all
                _GUICtrlRichEdit_SetSel($edt_Converted, 0, 0)           ; set cursor to start

                _WinAPI_SetFocus($edt_Service)
            Case $btn_convert
                _GUICtrlRichEdit_SetSel($edt_Converted, 0, -1, True)    ; select all, but hide
                _GUICtrlRichEdit_ReplaceText($edt_Converted, "")        ; replace all
                _GUICtrlRichEdit_SetSel($edt_Converted, 0, 0)           ; set cursor to start

                Local $iAll_Lines = _GUICtrlRichEdit_GetLineCount ( $edt_Service )
                Local $sConverted = ""
                Local $sText = ""

                If $iAll_Lines>0 Then
                    _GUICtrlRichEdit_AppendText ( $edt_Converted,  "@echo off" & @LF )
                    _GUICtrlRichEdit_AppendText ( $edt_Converted,  "echo Uptimize Services" & @LF )
                    _GUICtrlRichEdit_AppendText ( $edt_Converted,  "echo." & @LF )
                    _GUICtrlRichEdit_AppendText ( $edt_Converted,  "echo --Start-----------------------------------" & @LF )
                EndIf

                For $iLine = 1 To  $iAll_Lines

                    $sText = _GUICtrlRichEdit_GetTextInLine ( $edt_Service, $iLine )

                    If $sText<>"" Then

                        _GUICtrlRichEdit_AppendText ( $edt_Converted,  'echo Service Name :  '& $sText  & @LF )

                        If _IsChecked($chb_Stop) Then
                            $sConverted = _create_commandline($sText, "stop")
                            If $sConverted Then _GUICtrlRichEdit_AppendText ( $edt_Converted,  $sConverted & @LF )
                        EndIf

                        If _IsChecked($chb_Config) Then
                            Local $sSC_config = GUICtrlRead($cmb_config)
                            If $sSC_config = "" Then $sSC_config = Default
                            $sConverted = _create_commandline($sText, "config", $sSC_config)
                            If $sConverted Then _GUICtrlRichEdit_AppendText  ( $edt_Converted, $sConverted & @LF )
                        EndIf

                        If _IsChecked($chb_Start) Then
                            $sConverted = _create_commandline($sText, "start")
                            If $sConverted Then _GUICtrlRichEdit_AppendText ( $edt_Converted, $sConverted & @LF )
                        EndIf

                    EndIf

                Next

                If $iAll_Lines>0 Then
                    _GUICtrlRichEdit_AppendText ( $edt_Converted,  "echo --End-------------------------------------" & @LF )
                    _GUICtrlRichEdit_AppendText ( $edt_Converted,  "echo." & @LF )
                    _GUICtrlRichEdit_AppendText ( $edt_Converted,  "pause" & @LF )
                    _GUICtrlRichEdit_AppendText ( $edt_Converted,  "exit" & @LF )
                EndIf
        EndSwitch
    WEnd

    #Region ;Exit
        _GUICtrlRichEdit_Destroy($edt_Service)
        _GUICtrlRichEdit_Destroy($edt_Converted)
        GUIDelete($ConvertService)
        Exit
    #EndRegion ;Exit
EndFunc

Func _IsChecked($idControlID)
    Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_CHECKED
EndFunc   ;==>_IsChecked

Func _create_commandline($serviceName, $sSc_SW, $sSc_config_SW = Default)
    Local $sOutput = ""
    Local $oError = False
    Switch $sSc_SW
        Case "stop"
            $sOutput = "sc stop " & '"' & $serviceName & '"'
        Case "start"
            $sOutput = "sc start " & '"' & $serviceName & '"'
        Case "config"
            ;<boot|system|auto|demand|disabled|delayed-auto>
            Switch $sSc_config_SW
                Case 1, "boot"
                    $sOutput = "sc config " & '"' & $serviceName & '"' & " start= " & "boot"
                Case 2, "system"
                    $sOutput = "sc config " & '"' & $serviceName & '"' & " start= " & "system"
                Case 3, "auto", Default
                    $sOutput = "sc config " & '"' & $serviceName & '"' & " start= " & "auto"
                Case 4, "demand"
                    $sOutput = "sc config " & '"' & $serviceName & '"' & " start= " & "demand"
                Case 5, "disabled"
                    $sOutput = "sc config " & '"' & $serviceName & '"' & " start= " & "disabled"
                Case 6, "delayed-aut"
                    $sOutput = "sc config " & '"' & $serviceName & '"' & " start= " & "delayed-aut"
            EndSwitch
    EndSwitch
    If $sOutput Then Return $sOutput
    Return $oError
EndFunc

 

 

in GUIOnEventMode :

The order of execution of the commands was added

 

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiRichEdit.au3>

Opt("GUIOnEventMode", 1)

_Gui()



Func _Gui()
    Global $ConvertService =    GUICreate("ConvertService", 714, 416, 192, 124)
                                GUISetOnEvent($GUI_EVENT_CLOSE, "_onChange")
                                GUISetOnEvent($GUI_EVENT_MINIMIZE, "_onChange")

    Local $lbl_title        =   GUICtrlCreateLabel("Convert Service Name and CommandLine", 144, 24, 291, 20)
                                GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
                                GUICtrlSetColor(-1, 0x0078D7)


    Local $lbl_Service      =   GUICtrlCreateLabel("Services :", 73, 65, 73, 20)
                                GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
                                GUICtrlSetColor(-1, 0x0078D7)

    Global $edt_Service     =   _GUICtrlRichEdit_Create($ConvertService, "", 16, 91, 201, 297, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
                                _GUICtrlRichEdit_SetFont($edt_Service, 8, "MS Sans Serif")

    Global $btn_convert     =   GUICtrlCreateButton("Convert", 240, 192, 100, 25)
                                GUICtrlSetOnEvent(-1, "_onChange")
                                GUICtrlSetFont(-1, 10, 800, 0)

    Local $lbl_ScConfigs    =   GUICtrlCreateLabel("Sc Configs : ", 239, 227, 90, 20)
                                GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
                                GUICtrlSetColor(-1, 0x0078D7)

    Global $chb_Stop        =   GUICtrlCreateCheckbox("Stop", 240, 256, 97, 17)

    Global $chb_Start       =   GUICtrlCreateCheckbox("Start", 240, 280, 97, 17)

    Global $chb_Config      =   GUICtrlCreateCheckbox("Config", 240, 304, 97, 17)

    Global $cmb_config      =   GUICtrlCreateCombo("", 240, 328, 100, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
                                GUICtrlSetData(-1, "boot|system|auto|demand|disabled|delayed-auto")

    Global $btn_clear       =   GUICtrlCreateButton("Clear", 240, 328 + 25 + 7, 100, 25)
                                GUICtrlSetOnEvent(-1, "_onChange")


    Local $lbl_Converted    =   GUICtrlCreateLabel("Converted :", 446, 67, 83, 20)
                                GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
                                GUICtrlSetColor(-1, 0x0078D7)

    Global $edt_Converted   =   _GUICtrlRichEdit_Create($ConvertService, "", 382, 91, 313, 297, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL, $ES_READONLY ))
                                GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")

    _WinAPI_SetFocus($edt_Service)
    GUISetState(@SW_SHOW, $ConvertService)

    While 1
        Sleep(100)
    WEnd
EndFunc



Func _onChange()
    Switch @GUI_CtrlId
        Case $GUI_EVENT_CLOSE
            _GUICtrlRichEdit_Destroy($edt_Service)
            _GUICtrlRichEdit_Destroy($edt_Converted)
            GUIDelete($ConvertService)
            Exit

        Case $btn_clear
            _GUICtrlRichEdit_SetSel($edt_Service, 0, -1, True)    ; select all, but hide
            _GUICtrlRichEdit_ReplaceText($edt_Service, "")      ; replace all
            _GUICtrlRichEdit_SetSel($edt_Service, 0, 0)           ; set cursor to start

            _GUICtrlRichEdit_SetSel($edt_Converted, 0, -1, True)    ; select all, but hide
            _GUICtrlRichEdit_ReplaceText($edt_Converted, "")        ; replace all
            _GUICtrlRichEdit_SetSel($edt_Converted, 0, 0)           ; set cursor to

            _WinAPI_SetFocus($edt_Service)

        Case $btn_convert

                _GUICtrlRichEdit_SetSel($edt_Converted, 0, -1, True)    ; select all, but hide
                _GUICtrlRichEdit_ReplaceText($edt_Converted, "")        ; replace all
                _GUICtrlRichEdit_SetSel($edt_Converted, 0, 0)           ; set cursor to start

                Local $iAll_Lines = _GUICtrlRichEdit_GetLineCount ( $edt_Service )
                Local $sConverted = ""
                Local $sText = ""

                If $iAll_Lines>0 Then
                    _GUICtrlRichEdit_AppendText ( $edt_Converted,  "@echo off" & @LF )
                    _GUICtrlRichEdit_AppendText ( $edt_Converted,  "echo Uptimize Services" & @LF )
                    _GUICtrlRichEdit_AppendText ( $edt_Converted,  "echo." & @LF )
                    _GUICtrlRichEdit_AppendText ( $edt_Converted,  "echo --Start-----------------------------------" & @LF )
                EndIf

                For $iLine = 1 To  $iAll_Lines

                    $sText = _GUICtrlRichEdit_GetTextInLine ( $edt_Service, $iLine )

                    If $sText<>"" Then

                        _GUICtrlRichEdit_AppendText ( $edt_Converted,  'echo Service Name :  '& $sText  & @LF )

                        If _IsChecked($chb_Stop) Then
                            $sConverted = _create_commandline($sText, "stop")
                            If $sConverted Then _GUICtrlRichEdit_AppendText ( $edt_Converted,  $sConverted & @LF )
                        EndIf

                        If _IsChecked($chb_Config) Then
                            Local $sSC_config = GUICtrlRead($cmb_config)
                            If $sSC_config = "" Then $sSC_config = Default
                            $sConverted = _create_commandline($sText, "config", $sSC_config)
                            If $sConverted Then _GUICtrlRichEdit_AppendText  ( $edt_Converted, $sConverted & @LF )
                        EndIf

                        If _IsChecked($chb_Start) Then
                            $sConverted = _create_commandline($sText, "start")
                            If $sConverted Then _GUICtrlRichEdit_AppendText ( $edt_Converted, $sConverted & @LF )
                        EndIf

                    EndIf

                Next

                If $iAll_Lines>0 Then
                    _GUICtrlRichEdit_AppendText ( $edt_Converted,  "echo --End-------------------------------------" & @LF )
                    _GUICtrlRichEdit_AppendText ( $edt_Converted,  "echo." & @LF )
                    _GUICtrlRichEdit_AppendText ( $edt_Converted,  "pause" & @LF )
                    _GUICtrlRichEdit_AppendText ( $edt_Converted,  "exit" & @LF )
                EndIf

    EndSwitch
EndFunc




Func _IsChecked($idControlID)
    Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_CHECKED
EndFunc   ;==>_IsChecked


Func _create_commandline($serviceName, $sSc_SW, $sSc_config_SW = Default)
    Local $sOutput = ""
    Local $oError = False
    Switch $sSc_SW
        Case "stop"
            $sOutput = "sc stop " & '"' & $serviceName & '"'
        Case "start"
            $sOutput = "sc start " & '"' & $serviceName & '"'
        Case "config"
            ;<boot|system|auto|demand|disabled|delayed-auto>
            Switch $sSc_config_SW
                Case 1, "boot"
                    $sOutput = "sc config " & '"' & $serviceName & '"' & " start= " & "boot"
                Case 2, "system"
                    $sOutput = "sc config " & '"' & $serviceName & '"' & " start= " & "system"
                Case 3, "auto", Default
                    $sOutput = "sc config " & '"' & $serviceName & '"' & " start= " & "auto"
                Case 4, "demand"
                    $sOutput = "sc config " & '"' & $serviceName & '"' & " start= " & "demand"
                Case 5, "disabled"
                    $sOutput = "sc config " & '"' & $serviceName & '"' & " start= " & "disabled"
                Case 6, "delayed-aut"
                    $sOutput = "sc config " & '"' & $serviceName & '"' & " start= " & "delayed-aut"
            EndSwitch
    EndSwitch
    If $sOutput Then Return $sOutput
    Return $oError
EndFunc

 

Edited by Parsix
The order of execution of the commands was added
Link to post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...