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 に答える