Advertisement
hiro1357

NTP更新間隔設定2.vb

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