hiro1357 icon

NTP更新間隔設定.vb

hiro1357 | PRO | 11/25/15 07:17:54 AM UTC | 0 ⭐ | 339 👁️ | Never ⏰ | []
VB.NET |

2.9 KB

|

None

|

0 👍

/

0 👎

Imports System.Windows.Forms
Imports Microsoft.Win32
 
Public Class App
    Public Shared Form1 As New Form
    Public Shared WithEvents Button1 As New Button
    Public Shared TextBox1 As New TextBox
    Public Shared TextBox2 As New TextBox
    Public Shared Label1 As New Label
    Public Shared Label2 As New Label
 
 
    Public Shared NtpValue As Integer
 
    Shared Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        TextBox1.Text = CStr(CInt(TextBox1.Text))
        TextBox2.Text = CStr(CInt(TextBox2.Text))
        NtpValue = (CInt(TextBox1.Text) * 86400) + (CInt(TextBox2.Text) * 3600)
        If NtpValue < 3600 Then
            MessageBox.Show("値が小さすぎます。")
            Return
        End If
        If (MessageBox.Show("更新間隔を " + TextBox1.Text + "日 と " + TextBox2.Text + "時間 " + "(" + CStr(NtpValue) + "秒) おきに設定しますか?", "Question", MessageBoxButtons.YesNo)) = DialogResult.Yes Then
            Try
                Registry.SetValue("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\NtpClient\", "SpecialPollInterval", NtpValue, RegistryValueKind.DWord)
                MessageBox.Show("設定しました!")
            Catch
                MessageBox.Show("設定に失敗しました。管理者として実行し、もう一度お試しください。")
            End Try
        End If
    End Sub
 
    Public Shared Sub Main()
        NtpValue = Registry.GetValue("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\NtpClient\", "SpecialPollInterval", 0)
        If NtpValue = 0 Then
            MessageBox.Show("設定値の取得に失敗しました。デフォルト値をセットします。")
            NtpValue = 604800
        End If
 
        Form1.Text = "NTP 更新間隔設定"
        Form1.Width = 275
        Form1.Height = 100
        Form1.FormBorderStyle = FormBorderStyle.Fixed3D
 
 
        Button1.Text = "設定する"
        Button1.Top = 35
        Button1.Left = 90
 
        TextBox1.Multiline = False
        TextBox1.Left = 10
        TextBox1.Top = 10
        TextBox1.Width = 80
        TextBox1.ScrollBars = ScrollBars.None
        TextBox1.Text = CStr(NtpValue / 86400)
 
        TextBox2.Multiline = False
        TextBox2.Left = 130
        TextBox2.Top = 10
        TextBox2.Width = 80
        TextBox2.ScrollBars = ScrollBars.None
        TextBox2.Text = CStr((NtpValue Mod 86400) / 3600)
 
        Label1.Left = 90
        Label1.Top = 15
        Label1.Text = "日"
 
        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()
 
    End Sub
End Class

Comments