hiro1357 icon

NTP更新間隔設定.ps1

hiro1357 | PRO | 11/24/15 12:31:57 PM UTC | 0 ⭐ | 628 👁️ | Never ⏰ | []
PowerShell |

2.71 KB

|

None

|

0 👍

/

0 👎

Add-Type -AssemblyName System.Windows.Forms
 
$NtpValue = [Microsoft.Win32.Registry]::GetValue("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\NtpClient\", "SpecialPollInterval", 0)
If ($NtpValue -eq 0) {
    [Windows.Forms.MessageBox]::Show("設定値の取得に失敗しました。デフォルト値をセットします。")
    $NtpValue = 604800
}
Function Button1_Click() {
    $TextBox1.Text = [String]([Int]$TextBox1.Text)
    $TextBox2.Text = [String]([Int]$TextBox2.Text)
    $NtpValue = ([Int]$TextBox1.Text * 86400) + ([Int]$TextBox2.Text * 3600)
    If ($NtpValue -lt 3600) {
        [Windows.Forms.MessageBox]::Show("値が小さすぎます。")
        Return
    }
    If ([Windows.Forms.MessageBox]::Show("更新間隔を " + $TextBox1.Text + "日 と " + $TextBox2.Text + "時間 " + "(" + $NtpValue + "秒) おきに設定しますか?", "Question", [Windows.Forms.MessageBoxButtons]::YesNo) -eq [Windows.Forms.DialogResult]::Yes) {
        Try {
            [Microsoft.Win32.Registry]::SetValue("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\NtpClient\", "SpecialPollInterval", $NtpValue, [Microsoft.Win32.RegistryValueKind]::DWord)
            [Windows.Forms.MessageBox]::Show("設定しました!")
        } Catch {
            [Windows.Forms.MessageBox]::Show("設定に失敗しました。管理者として実行し、もう一度お試しください。")
        }
    }
}
 
$Form1 = New-Object System.Windows.Forms.Form
$Form1.Text = "NTP 更新間隔設定"
$Form1.Width = 275
$Form1.Height = 100
$Form1.FormBorderStyle = [Windows.Forms.FormBorderStyle]::Fixed3D
 
$Button1 = New-Object System.Windows.Forms.Button
$Button1.Text = "設定する"
$Button1.Top = 35
$Button1.Left = 90
$Button1.Add_Click({Button1_Click})
 
$TextBox1 = New-Object System.Windows.Forms.TextBox
$TextBox1.Multiline = $False
$TextBox1.Left = 10
$TextBox1.Top = 10
$TextBox1.Width = 80
$TextBox1.ScrollBars = [System.Windows.Forms.ScrollBars]::None
$TextBox1.Text = [String]($NtpValue / 86400)
 
$TextBox2 = New-Object System.Windows.Forms.TextBox
$TextBox2.Multiline = $False
$TextBox2.Left = 130
$TextBox2.Top = 10
$TextBox2.Width = 80
$TextBox2.ScrollBars = [System.Windows.Forms.ScrollBars]::None
$TextBox2.Text = [String](($NtpValue % 86400) / 3600)
 
$Label1 = New-Object System.Windows.Forms.Label
$Label1.Left = 90
$Label1.Top = 15
$Label1.Text = "日"
 
$Label2 = New-Object System.Windows.Forms.Label
$Label2.Left = 210
$Label2.Top = 15
$Label2.Text = "時間"
 
 
$Form1.Controls.Add($Button1)
$Form1.Controls.Add($TextBox1)
$Form1.Controls.Add($TextBox2)
$Form1.Controls.Add($Label1)
$Form1.Controls.Add($Label2)
$Form1.ShowDialog()

Comments