Advertisement
hiro1357

NTP更新間隔設定.vb

Nov 25th, 2015
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.90 KB | None | 0 0
  1. Imports System.Windows.Forms
  2. Imports Microsoft.Win32
  3.  
  4. Public Class App
  5.     Public Shared Form1 As New Form
  6.     Public Shared WithEvents Button1 As New Button
  7.     Public Shared TextBox1 As New TextBox
  8.     Public Shared TextBox2 As New TextBox
  9.     Public Shared Label1 As New Label
  10.     Public Shared Label2 As New Label
  11.  
  12.  
  13.     Public Shared NtpValue As Integer
  14.  
  15.     Shared Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
  16.         TextBox1.Text = CStr(CInt(TextBox1.Text))
  17.         TextBox2.Text = CStr(CInt(TextBox2.Text))
  18.         NtpValue = (CInt(TextBox1.Text) * 86400) + (CInt(TextBox2.Text) * 3600)
  19.         If NtpValue < 3600 Then
  20.             MessageBox.Show("値が小さすぎます。")
  21.             Return
  22.         End If
  23.         If (MessageBox.Show("更新間隔を " + TextBox1.Text + "日 と " + TextBox2.Text + "時間 " + "(" + CStr(NtpValue) + "秒) おきに設定しますか?", "Question", MessageBoxButtons.YesNo)) = DialogResult.Yes Then
  24.             Try
  25.                 Registry.SetValue("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\NtpClient\", "SpecialPollInterval", NtpValue, RegistryValueKind.DWord)
  26.                 MessageBox.Show("設定しました!")
  27.             Catch
  28.                 MessageBox.Show("設定に失敗しました。管理者として実行し、もう一度お試しください。")
  29.             End Try
  30.         End If
  31.     End Sub
  32.  
  33.     Public Shared Sub Main()
  34.         NtpValue = Registry.GetValue("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\NtpClient\", "SpecialPollInterval", 0)
  35.         If NtpValue = 0 Then
  36.             MessageBox.Show("設定値の取得に失敗しました。デフォルト値をセットします。")
  37.             NtpValue = 604800
  38.         End If
  39.  
  40.         Form1.Text = "NTP 更新間隔設定"
  41.         Form1.Width = 275
  42.         Form1.Height = 100
  43.         Form1.FormBorderStyle = FormBorderStyle.Fixed3D
  44.  
  45.  
  46.         Button1.Text = "設定する"
  47.         Button1.Top = 35
  48.         Button1.Left = 90
  49.  
  50.         TextBox1.Multiline = False
  51.         TextBox1.Left = 10
  52.         TextBox1.Top = 10
  53.         TextBox1.Width = 80
  54.         TextBox1.ScrollBars = ScrollBars.None
  55.         TextBox1.Text = CStr(NtpValue / 86400)
  56.  
  57.         TextBox2.Multiline = False
  58.         TextBox2.Left = 130
  59.         TextBox2.Top = 10
  60.         TextBox2.Width = 80
  61.         TextBox2.ScrollBars = ScrollBars.None
  62.         TextBox2.Text = CStr((NtpValue Mod 86400) / 3600)
  63.  
  64.         Label1.Left = 90
  65.         Label1.Top = 15
  66.         Label1.Text = "日"
  67.  
  68.         Label2.Left = 210
  69.         Label2.Top = 15
  70.         Label2.Text = "時間"
  71.  
  72.  
  73.         Form1.Controls.Add(Button1)
  74.         Form1.Controls.Add(TextBox1)
  75.         Form1.Controls.Add(TextBox2)
  76.         Form1.Controls.Add(Label1)
  77.         Form1.Controls.Add(Label2)
  78.  
  79.         Form1.ShowDialog()
  80.  
  81.     End Sub
  82. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement