Advertisement
hiro1357

NTP更新間隔設定3.vb

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