Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\vbc /out:test.exe test.vb
- Imports System.Windows.Forms
- Imports Microsoft.Win32
- Public Class Form1
- Inherits Form
- Private components As System.ComponentModel.IContainer
- Friend WithEvents Button1 As New Button
- Friend TextBox1 As New TextBox
- Friend TextBox2 As New TextBox
- Friend Label1 As New Label
- Friend Label2 As New Label
- Private NtpValue As Integer
- Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
- NtpValue = Registry.GetValue("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\NtpClient\", "SpecialPollInterval", 0)
- If NtpValue = 0 Then
- MessageBox.Show("設定値の取得に失敗しました。デフォルト値をセットします。")
- NtpValue = 604800
- End If
- End Sub
- Private 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
- Protected Overrides Sub Dispose(ByVal disposing As Boolean)
- Try
- If disposing AndAlso components IsNot Nothing Then
- components.Dispose()
- End If
- Finally
- MyBase.Dispose(disposing)
- End Try
- End Sub
- Sub New()
- Me.SuspendLayout()
- Me.Text = "NTP 更新間隔設定"
- Me.Width = 275
- Me.Height = 100
- Me.FormBorderStyle = FormBorderStyle.Fixed3D
- Me.Button1.Text = "設定する"
- Me.Button1.Top = 35
- Me.Button1.Left = 90
- Me.TextBox1.Multiline = False
- Me.TextBox1.Left = 10
- Me.TextBox1.Top = 10
- Me.TextBox1.Width = 80
- Me.TextBox1.ScrollBars = ScrollBars.None
- Me.TextBox1.Text = CStr(NtpValue / 86400)
- Me.TextBox2.Multiline = False
- Me.TextBox2.Left = 130
- Me.TextBox2.Top = 10
- Me.TextBox2.Width = 80
- Me.TextBox2.ScrollBars = ScrollBars.None
- Me.TextBox2.Text = CStr((NtpValue Mod 86400) / 3600)
- Me.Label1.Left = 90
- Me.Label1.Top = 15
- Me.Label1.Text = "日"
- Me.Label2.Left = 210
- Me.Label2.Top = 15
- Me.Label2.Text = "時間"
- Me.ResumeLayout(False)
- Me.Controls.Add(Button1)
- Me.Controls.Add(TextBox1)
- Me.Controls.Add(TextBox2)
- Me.Controls.Add(Label1)
- Me.Controls.Add(Label2)
- End Sub
- End Class
- Public Class App
- Shared WithEvents Form1_Instance As New Form1
- Public Shared Sub Main()
- Form1_Instance.ShowDialog()
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement