Jump to content

ControlSend() issue with server console

Recommended Posts

*Repost in honor of the forum rules*

The issue:

I wrote a script, that uses ControlSend() for stopping the server and sometimes announce the next server restart, through the console.

So far everything works fine, except that when I leave the remote desktop connection to my server, then the strings are not case-sensitive anymore and / for example becomes 7. For the commands, that does not matter too much, as it send 7 instead of / and in the console you can run commands without slash, so I just removed those.

As for the messages though:
next server restart at 06.30 cest


I searched a lot about this particular issue, but have found no solution so far. I am kinda like an advanced beginner, I have some roots in scripting/programming, but I never followed that path enough, to become advanced in it. Recently I found AutoIt and fell in love with its simplicity and that it just works for simple things, which it does for me. (almost ;D)

Any tiny bit could help me create this reliable script, which I would want to post somewhere for fellow people around the world, so that they can use this for themselves.


Thanks for any help in advance and here is my script:

Pls dont judge my beginner skills 😅

#cs ----------------------------------------------------------------------------

 AutoIt Version:
 Author:         Thalez

 Script Function:
    Automatically restart a Server on a Daily basis. (every 8 hours)

#ce ----------------------------------------------------------------------------

; Live Variables

Global $IsServerRestarting = False
Global $RestartAdCounter = 0

; Variables for customizing the script  <--------

; Server Console Window
Global $ConsoleWindowName = "DnDnS Server" ; It is required that you have this set correct

; Misc
Global $RestartAdText = "NEXT SERVER RESTART AT"

; Restart Advertisements
Global $RestartAdToggle = True ; Turn the restard advertisements on or off
Global $RestartAdInterval = 20 ; Minutes | How often you want to advertise the next restart
Global $TimeFormat = "CEST" ; The current time format

; Turn a restart scheduler on or off (Potentially breaks the restart advertisements)
Global $Restarter1 = True
Global $Restarter2 = True
Global $Restarter3 = True

;Restarter 1
Global $Restarter1TimeH = '06' ; Hour/24
Global $Restarter1TimeM = '25' ; Minute (MINUS 5)

;Restarter 2
Global $Restarter2TimeH = '14' ; Hour/24
Global $Restarter2TimeM = '25' ; Minute (MINUS 5)

;Restarter 3
Global $Restarter3TimeH = '22' ; Hour/24
Global $Restarter3TimeM = '25' ; Minute (MINUS 5)

; Variables for customizing the script  <--------

;Confirm Initiation
ControlFocus($ConsoleWindowName, "", "")
ControlSend($ConsoleWindowName, "", "", "say AUTO-RESTART SCRIPT LOADED")
ControlSend($ConsoleWindowName, "", "", "{ENTER}")

; Running Script
While 1

    ; A scheduled announcement for the next restart (Has to be rewritten, depending on the restart schedulers, that are turned on)
    If $RestartAdCounter = $RestartAdInterval * 4 and $IsServerRestarting = False Then

        $RestartAdCounter = 0

        ; Next Restarter 1
        If @HOUR >= 23 or @HOUR < 7 Then
                AnnounceRestart("06", "30")

        ; Next Restarter 2
        If @HOUR >= 7 and @HOUR < 15 Then
                AnnounceRestart("14", "30")

        ; Next Restarter 3
        If @HOUR >= 15 and @HOUR < 23 Then
                AnnounceRestart("22", "30")


    ; Actual Server Restart 1
    If $RestartAdToggle = True and $Restarter1 = True and @HOUR = $Restarter1TimeH and @MIN = $Restarter1TimeM and $IsServerRestarting = False Then
        $IsServerRestarting = True
    ; Actual Server Restart 2
    If $RestartAdToggle = True and $Restarter2 = True and @HOUR = $Restarter2TimeH and @MIN = $Restarter2TimeM and $IsServerRestarting = False Then
        $IsServerRestarting = True
    ; Actual Server Restart 3
    If $RestartAdToggle = True and $Restarter3 = True and @HOUR = $Restarter3TimeH and @MIN = $Restarter3TimeM and $IsServerRestarting = False Then
        $IsServerRestarting = True

$RestartAdCounter += 1
Sleep(15000) ; Update interval = 15 seconds



; /stop the server after 5 minutes, with announcements
Func RestartServer()

    ControlFocus($ConsoleWindowName, "", "")

    ControlSend($ConsoleWindowName, "", "", "say SERVER RESTART IN 5 MINUTES")
    ControlSend($ConsoleWindowName, "", "", "{ENTER}")
    ControlSend($ConsoleWindowName, "", "", "say SERVER RESTART IN 2 MINUTES")
    ControlSend($ConsoleWindowName, "", "", "{ENTER}")
    ControlSend($ConsoleWindowName, "", "", "say SERVER RESTART IN 1 MINUTE")
    ControlSend($ConsoleWindowName, "", "", "{ENTER}")
    ControlSend($ConsoleWindowName, "", "", "say SERVER RESTART IN 30 SECONDS")
    ControlSend($ConsoleWindowName, "", "", "{ENTER}")
    ControlSend($ConsoleWindowName, "", "", "say SERVER RESTART IN 10 SECONDS")
    ControlSend($ConsoleWindowName, "", "", "{ENTER}")
    ControlSend($ConsoleWindowName, "", "", "say 9..{ENTER}")
    ControlSend($ConsoleWindowName, "", "", "say 8..{ENTER}")
    ControlSend($ConsoleWindowName, "", "", "say 7..{ENTER}")
    ControlSend($ConsoleWindowName, "", "", "say 6..{ENTER}")
    ControlSend($ConsoleWindowName, "", "", "say 5..{ENTER}")
    ControlSend($ConsoleWindowName, "", "", "say 4..{ENTER}")
    ControlSend($ConsoleWindowName, "", "", "say 3..{ENTER}")
    ControlSend($ConsoleWindowName, "", "", "say 2..{ENTER}")
    ControlSend($ConsoleWindowName, "", "", "say 1..{ENTER}")
    ControlSend($ConsoleWindowName, "", "", "stop{ENTER}")



Func ResetIsServerRestarting() ; After 5 minutes delay
    $IsServerRestarting = False

; Announce the next restart, with Hour and Minute input
Func AnnounceRestart($H, $M)

    ControlFocus($ConsoleWindowName, "", "")

    ControlSend($ConsoleWindowName, "", "", "say ")
    ControlSend($ConsoleWindowName, "", "", $RestartAdText)
    ControlSend($ConsoleWindowName, "", "", " ")
    ControlSend($ConsoleWindowName, "", "", $H)
    ControlSend($ConsoleWindowName, "", "", ":")
    ControlSend($ConsoleWindowName, "", "", $M)
    ControlSend($ConsoleWindowName, "", "", " ")
    ControlSend($ConsoleWindowName, "", "", $TimeFormat)
    ControlSend($ConsoleWindowName, "", "", "{ENTER}")


; Just a function to put in, whenever you want to test something
Func TestFunc()

    ControlFocus($ConsoleWindowName, "", "")

    ControlSend($ConsoleWindowName, "", "", "say test{ENTER}")



Link to post
Share on other sites

The request and the script are almost completely identical to your already locked thread :


The only difference is, that you omitted the term Minecraft.

1 hour ago, Thalez said:

*Repost in honor of the forum rules*

With this repost, the forum rules are hardly honoured, but rather ridiculed :'(.

Edited by Musashi


"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to post
Share on other sites
  • Moderators


I see you did not read those rules to which you were linked very carefully - you missed the part that says:

"Do not repost the same question if the previous thread has been locked - particularly if you merely reword the question to get around one of the prohibitions listed above"

Do NOT start another thread on this - our patience has limits.


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:


ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area


Link to post
Share on other sites
This topic is now closed to further replies.
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...