Advertisement
hiro1357

NTP更新間隔設定.ps1

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