Advertisement
Guest User

FaUst

a guest
May 7th, 2016
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #region Script Settings
  2. #<ScriptSettings xmlns="http://tempuri.org/ScriptSettings.xsd">
  3. #  <ScriptPackager>
  4. #    <process>powershell.exe</process>
  5. #    <arguments />
  6. #    <extractdir>%TEMP%</extractdir>
  7. #    <files />
  8. #    <usedefaulticon>true</usedefaulticon>
  9. #    <showinsystray>false</showinsystray>
  10. #    <altcreds>false</altcreds>
  11. #    <efs>true</efs>
  12. #    <ntfs>true</ntfs>
  13. #    <local>false</local>
  14. #    <abortonfail>true</abortonfail>
  15. #    <product />
  16. #    <version>1.0.0.1</version>
  17. #    <versionstring />
  18. #    <comments />
  19. #    <company />
  20. #    <includeinterpreter>false</includeinterpreter>
  21. #    <forcecomregistration>false</forcecomregistration>
  22. #    <consolemode>false</consolemode>
  23. #    <EnableChangelog>false</EnableChangelog>
  24. #    <AutoBackup>false</AutoBackup>
  25. #    <snapinforce>false</snapinforce>
  26. #    <snapinshowprogress>false</snapinshowprogress>
  27. #    <snapinautoadd>2</snapinautoadd>
  28. #    <snapinpermanentpath />
  29. #    <cpumode>1</cpumode>
  30. #    <hidepsconsole>false</hidepsconsole>
  31. #  </ScriptPackager>
  32. #</ScriptSettings>
  33. #endregion
  34.  
  35. #region ScriptForm Designer
  36.  
  37. #region Constructor
  38.  
  39. [void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
  40. [void][System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
  41.  
  42. #endregion
  43.  
  44. #region Post-Constructor Custom Code
  45.  
  46. #endregion
  47.  
  48. #region Form Creation
  49. #Warning: It is recommended that changes inside this region be handled using the ScriptForm Designer.
  50. #When working with the ScriptForm designer this region and any changes within may be overwritten.
  51. #~~< Form1 >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  52. $Form1 = New-Object System.Windows.Forms.Form
  53. $Form1.AutoSize = $true
  54. $Form1.ClientSize = New-Object System.Drawing.Size(292, 104)
  55. $Form1.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedDialog
  56. $Form1.MaximizeBox = $false
  57. $Form1.Text = "Set default VPN gateway"
  58. #~~< btnSplitDisable >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  59. $btnSplitDisable = New-Object System.Windows.Forms.Button
  60. $btnSplitDisable.Enabled = $false
  61. $btnSplitDisable.Location = New-Object System.Drawing.Point(160, 64)
  62. $btnSplitDisable.Size = New-Object System.Drawing.Size(112, 23)
  63. $btnSplitDisable.TabIndex = 4
  64. $btnSplitDisable.Text = "ENABLE"
  65. $btnSplitDisable.UseVisualStyleBackColor = $true
  66. $btnSplitDisable.add_Click({btnSplitDisable_click($btnSplitDisable)})
  67. #~~< btnSplitEnable >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  68. $btnSplitEnable = New-Object System.Windows.Forms.Button
  69. $btnSplitEnable.Enabled = $false
  70. $btnSplitEnable.Location = New-Object System.Drawing.Point(16, 64)
  71. $btnSplitEnable.Size = New-Object System.Drawing.Size(112, 23)
  72. $btnSplitEnable.TabIndex = 3
  73. $btnSplitEnable.Text = "DISABLE"
  74. $btnSplitEnable.UseVisualStyleBackColor = $true
  75. $btnSplitEnable.add_Click({btnSplitEnable_click($btnSplitEnable)})
  76. #~~< lblSplitTunellingStatus >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  77. $lblSplitTunellingStatus = New-Object System.Windows.Forms.Label
  78. $lblSplitTunellingStatus.Location = New-Object System.Drawing.Point(16, 32)
  79. $lblSplitTunellingStatus.Size = New-Object System.Drawing.Size(256, 23)
  80. $lblSplitTunellingStatus.TabIndex = 2
  81. $lblSplitTunellingStatus.Text = ""
  82. $lblSplitTunellingStatus.TextAlign = [System.Drawing.ContentAlignment]::MiddleCenter
  83. #~~< Label1 >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  84. $Label1 = New-Object System.Windows.Forms.Label
  85. $Label1.Location = New-Object System.Drawing.Point(10, 8)
  86. $Label1.Size = New-Object System.Drawing.Size(64, 23)
  87. $Label1.TabIndex = 1
  88. $Label1.Text = "Select vpn:"
  89. $Label1.TextAlign = [System.Drawing.ContentAlignment]::MiddleCenter
  90. #~~< cbVPNName >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  91. $cbVPNName = New-Object System.Windows.Forms.ComboBox
  92. $cbVPNName.FormattingEnabled = $true
  93. $cbVPNName.Location = New-Object System.Drawing.Point(74, 8)
  94. $cbVPNName.SelectedIndex = -1
  95. $cbVPNName.Size = New-Object System.Drawing.Size(200, 21)
  96. $cbVPNName.TabIndex = 0
  97. $cbVPNName.Text = ""
  98. $cbVPNName.add_SelectedIndexChanged({cbVPNName_changed($cbVPNName)})
  99. $Form1.Controls.Add($btnSplitDisable)
  100. $Form1.Controls.Add($btnSplitEnable)
  101. $Form1.Controls.Add($lblSplitTunellingStatus)
  102. $Form1.Controls.Add($Label1)
  103. $Form1.Controls.Add($cbVPNName)
  104.  
  105. #endregion
  106.  
  107. #region Custom Code
  108. $VPN = Get-VpnConnection | select name
  109. foreach ($vpnname in $VPN)
  110. {
  111.     $cbVPNName.Items.Add($vpnname.name)
  112. }
  113. #endregion
  114.  
  115. #region Event Loop
  116.  
  117. function Main{
  118.     [System.Windows.Forms.Application]::EnableVisualStyles()
  119.     [System.Windows.Forms.Application]::Run($Form1)
  120. }
  121.  
  122. #endregion
  123.  
  124. #endregion
  125.  
  126. #region Event Handlers
  127.  
  128.  
  129. function cbVPNName_changed($object){
  130.     try
  131.     {
  132.         $selectedVPN = $cbVPNName.SelectedItem
  133.         $status = Get-VPNConnection -name $selectedVPN
  134.         if ($status.SplitTunneling -eq $true)
  135.         {
  136.             $lblSplitTunellingStatus.Text = "VPN isn't a default gateway"
  137.             $btnSplitEnable.Enabled = $false
  138.             $btnSplitDisable.Enabled = $true
  139.         }
  140.         elseif ($status.SplitTunneling -eq $false)
  141.         {
  142.             $lblSplitTunellingStatus.Text = "VPN is a default gateway"
  143.             $btnSplitEnable.Enabled = $true
  144.             $btnSplitDisable.Enabled = $false
  145.         }
  146.     }
  147.     catch
  148.     {
  149.         [System.Windows.Forms.MessageBox]::Show("VPN connection do not exist", "Error", "OK", "Error")
  150.     }
  151. }
  152.  
  153. function btnSplitDisable_click( $object ){
  154.     try
  155.     {
  156.         $selectedVPN = $cbVPNName.SelectedItem
  157.         set-VpnConnection -name $selectedVPN -SplitTunneling $false
  158.         $lblSplitTunellingStatus.Text = "VPN is a default gateway"
  159.         $btnSplitDisable.Enabled = $false
  160.         $btnSplitEnable.Enabled = $true
  161.     }
  162.     catch
  163.     {
  164.         [System.Windows.Forms.MessageBox]::Show("VPN connection do not exist", "Error", "OK", "Error")
  165.     }
  166.    
  167. }
  168.  
  169. function btnSplitEnable_click( $object ){
  170.     try
  171.     {
  172.         $selectedVPN = $cbVPNName.SelectedItem
  173.         set-VpnConnection -name $selectedVPN -SplitTunneling $true
  174.         $lblSplitTunellingStatus.Text = "VPN isn't a default gateway"
  175.         $btnSplitEnable.Enabled = $false
  176.         $btnSplitDisable.Enabled = $true
  177.     }
  178.     catch
  179.     {
  180.         [System.Windows.Forms.MessageBox]::Show("VPN connection do not exist", "Error", "OK", "Error")
  181.     }
  182.        
  183. }
  184.  
  185. Main # This call must remain below all other event functions
  186.  
  187. #endregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement