0

我正在尝试设置一个程序,该程序将在主机的时间达到某个小时或分钟时运行一个功能。似乎我需要一些东西来检查时间,但不要阻止任何东西。函数 Say() 是一个示例,它显示在某个时间点,将触发一个函数。Backup() 是我想备份文件夹并将名称更改为创建日期的函数。我不知道我将如何让时间工作。有什么建议么?

#include <ComboConstants.au3>
#include <StaticConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
#include <Date.au3>

Global $hwnd, $pid, $Server, $time, $min, $sec, $hour, $Counter, $s_Source, $s_Destination, $i_Flag
MsgBox(0, "Test", Time())
Start()
While 1
If $Server = "Running" Then
    If ProcessWaitClose($pid) = 1 Then Exit
EndIf
If $time = "20:15:00" Then Say()
WEnd

Func Start()
If @error Then
    Sleep(1)
Else
    Run('java -jar -Xmx1024M "C:\Users\Kristian\Desktop\Minecraft Server\minecraft_server.jar"', "C:\Users\Kristian\Desktop\Minecraft Server\", @SW_SHOW)
    Sleep(1000)
    WinSetTitle("C:\Windows\system32\java.exe", "", "MCS")
    WinSetTitle("C:\Windows\SYSTEM32\java.exe", "", "MCS")
    Global $hwnd = WinGetHandle("MCS")
    Global $pid = WinGetProcess("MCS")
    Sleep(1000)
    Global $Server = "Running"
    Sleep(10000)
EndIf
EndFunc   ;==>Start

Func Say()
WinActivate($hwnd)
Sleep(1000)
ControlSend("MCS", "", $hwnd, 'say Hello')
Sleep(1000)
ControlSend("MCS", "", $hwnd, '{ENTER}')
Sleep(1000)
EndFunc   ;==>Say


Func Backup()
$Counter += 1
DirCreate("C:\ServerBackups")
FileCopy("C:\Users\Kristian\Desktop\Minecraft Server\world\*.*", "C:\ServerBackups\")
_FileRename_($s_Source, $s_Destination, $i_Flag = $time)
EndFunc   ;==>Backup

Func _FileRename_($s_Source, $s_Destination, $i_Flag = $time)
Local $i
$i = FileMove($s_Source, $s_Destination, $i_Flag)
Return $i
EndFunc   ;==>_FileRename_

Func Time()
$min = @MIN
$sec = @SEC
$hour = @HOUR
$time = $hour & ":" & $min & ":" & $sec
Return $time
EndFunc   ;==>Time

我从建议中得出的结论:

Global $Server, $pid, $time, $save = 0
$Read = RegRead("HKEY_CURRENT_USER\Software\KnarCraft", "Version")
$Path1 = @TempDir & "\versions.json"
If Not InetGet("https://s3.amazonaws.com/Minecraft.Download/versions/versions.json", $Path1, 1, 0) = 0 Then $FF = FileOpen($Path1)
$RF = FileReadLine($FF, 3)
If $Read = $RF And FileExists("E:\Spill\Alle spill\Minecraft\Tools\YAMS\servers\7\minecraft_server.jar") Then
Else
    $ver1 = StringReplace($RF, '    "snapshot": "', "")
    $ver = StringReplace($ver1, '",', "")
    If InetGet('https://s3.amazonaws.com/Minecraft.Download/versions/' & $ver & "/minecraft_server." & $ver & ".jar", "E:\Spill\Alle spill\Minecraft\Tools\YAMS\servers\7\minecraft_server.jar", 1, 0) = 1 Then RegWrite("HKEY_CURRENT_USER\Software\KnarCraft", "Version", "REG_SZ", $RF)
EndIf
FileDelete($Path1)
$2 = Run('java -jar -Xmx3072M "E:\Spill\Alle spill\Minecraft\Tools\YAMS\servers\7\minecraft_server.jar"', "E:\Spill\Alle spill\Minecraft\Tools\YAMS\servers\7\", @SW_HIDE)
If Not ProcessWait($2) = 0 Then WinSetTitle("C:\Windows\system32\java.exe", "", "MCS")
Global $hwnd = WinGetHandle("MCS"), $pid = WinGetProcess("MCS"), $Server = "Running"
While 1
    AdlibRegister("Checktime", 1000)
    If $Server = "Running" And ProcessWaitClose($pid) = 1 Then Exit
WEnd
Func Checktime()
    If @MIN = 00 Or @MIN = 10 Or @MIN = 20 Or @MIN = 30 Or @MIN = 40 Or @MIN = 50 And @SEC = 00 Then ControlSend("MCS", "", $hwnd, 'say Report bugs and errors here: http://knar.world-servers.com/f6-problems-and-suggestions' & '{ENTER}')
    If @MIN = 05 Or @MIN = 15 Or @MIN = 25 Or @MIN = 35 Or @MIN = 45 Or @MIN = 55 And @SEC = 00 Then ControlSend("MCS", "", $hwnd, 'say Warning: Server may be unstable' & '{ENTER}')
    If @MIN = 37 And @SEC = 00 Then
        If ControlSend("MCS", "", $hwnd, "say Commencing Backup" & '{ENTER}') = 1 Then RunWait(@ComSpec & ' /c xcopy /e /c /h /i /v /r /y /q "' & "E:\Spill\Alle spill\Minecraft\Tools\YAMS\servers\7\world" & '" "' & "E:\Spill\Alle spill\Minecraft\Tools\YAMS\servers\7\backup\" & @MDAY & "-" & @MON & "-" & @YEAR & "-" & @HOUR & "-" & @MIN & "H" & "\world" & '"')
    EndIf
    If @HOUR = 20 And @MIN = 15 Then
        If ControlSend("MCS", "", $hwnd, "say Commencing Backup" & '{ENTER}') = 1 Then RunWait(@ComSpec & ' /c xcopy /e /c /h /i /v /r /y /q "' & "E:\Spill\Alle spill\Minecraft\Tools\YAMS\servers\7\world" & '" "' & "E:\Spill\Alle spill\Minecraft\Tools\YAMS\servers\7\backup\" & @MDAY & "-" & @MON & "-" & @YEAR & "-" & @HOUR & "-" & @MIN & "D" & "\world" & '"')
    EndIf
    If @HOUR = 00 And @MIN = 00 Then
        If ControlSend("MCS", "", $hwnd, "say Restarting Server" & '{ENTER}' & "stop" & '{ENTER}') = 1 Then Shutdown(2)
    EndIf
    If @MIN = 00 Or @MIN = 05 Or @MIN = 10 Or @MIN = 15 Or @MIN = 20 Or @MIN = 25 Or @MIN = 30 Or @MIN = 35 Or @MIN = 40 Or @MIN = 45 Or @MIN = 50 Or @MIN = 55 And @SEC = 07 Then ControlSend("MCS", "", $hwnd, 'say Saving World' & '{ENTER}' & 'save-all' & '{ENTER}')
EndFunc   ;==>Checktime
4

1 回答 1

0

只需更换

If $time = "20:15:00" Then Say()

If Time() = "20:15:00" Then Say()

干杯

于 2013-10-17T13:31:53.423 回答