Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #region Script Settings
- #<ScriptSettings xmlns="http://tempuri.org/ScriptSettings.xsd">
- # <ScriptPackager>
- # <process>powershell.exe</process>
- # <arguments />
- # <extractdir>%TEMP%</extractdir>
- # <files />
- # <usedefaulticon>true</usedefaulticon>
- # <showinsystray>false</showinsystray>
- # <altcreds>false</altcreds>
- # <efs>true</efs>
- # <ntfs>true</ntfs>
- # <local>false</local>
- # <abortonfail>true</abortonfail>
- # <product />
- # <version>1.0.0.1</version>
- # <versionstring />
- # <comments />
- # <company />
- # <includeinterpreter>false</includeinterpreter>
- # <forcecomregistration>false</forcecomregistration>
- # <consolemode>false</consolemode>
- # <EnableChangelog>false</EnableChangelog>
- # <AutoBackup>false</AutoBackup>
- # <snapinforce>false</snapinforce>
- # <snapinshowprogress>false</snapinshowprogress>
- # <snapinautoadd>2</snapinautoadd>
- # <snapinpermanentpath />
- # <cpumode>1</cpumode>
- # <hidepsconsole>false</hidepsconsole>
- # </ScriptPackager>
- #</ScriptSettings>
- #endregion
- #region ScriptForm Designer
- #region Constructor
- [void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
- [void][System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
- #endregion
- #region Post-Constructor Custom Code
- #endregion
- #region Form Creation
- #Warning: It is recommended that changes inside this region be handled using the ScriptForm Designer.
- #When working with the ScriptForm designer this region and any changes within may be overwritten.
- #~~< Form1 >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- $Form1 = New-Object System.Windows.Forms.Form
- $Form1.AutoSize = $true
- $Form1.ClientSize = New-Object System.Drawing.Size(292, 104)
- $Form1.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedDialog
- $Form1.MaximizeBox = $false
- $Form1.Text = "Set default VPN gateway"
- #~~< btnSplitDisable >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- $btnSplitDisable = New-Object System.Windows.Forms.Button
- $btnSplitDisable.Enabled = $false
- $btnSplitDisable.Location = New-Object System.Drawing.Point(160, 64)
- $btnSplitDisable.Size = New-Object System.Drawing.Size(112, 23)
- $btnSplitDisable.TabIndex = 4
- $btnSplitDisable.Text = "ENABLE"
- $btnSplitDisable.UseVisualStyleBackColor = $true
- $btnSplitDisable.add_Click({btnSplitDisable_click($btnSplitDisable)})
- #~~< btnSplitEnable >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- $btnSplitEnable = New-Object System.Windows.Forms.Button
- $btnSplitEnable.Enabled = $false
- $btnSplitEnable.Location = New-Object System.Drawing.Point(16, 64)
- $btnSplitEnable.Size = New-Object System.Drawing.Size(112, 23)
- $btnSplitEnable.TabIndex = 3
- $btnSplitEnable.Text = "DISABLE"
- $btnSplitEnable.UseVisualStyleBackColor = $true
- $btnSplitEnable.add_Click({btnSplitEnable_click($btnSplitEnable)})
- #~~< lblSplitTunellingStatus >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- $lblSplitTunellingStatus = New-Object System.Windows.Forms.Label
- $lblSplitTunellingStatus.Location = New-Object System.Drawing.Point(16, 32)
- $lblSplitTunellingStatus.Size = New-Object System.Drawing.Size(256, 23)
- $lblSplitTunellingStatus.TabIndex = 2
- $lblSplitTunellingStatus.Text = ""
- $lblSplitTunellingStatus.TextAlign = [System.Drawing.ContentAlignment]::MiddleCenter
- #~~< Label1 >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- $Label1 = New-Object System.Windows.Forms.Label
- $Label1.Location = New-Object System.Drawing.Point(10, 8)
- $Label1.Size = New-Object System.Drawing.Size(64, 23)
- $Label1.TabIndex = 1
- $Label1.Text = "Select vpn:"
- $Label1.TextAlign = [System.Drawing.ContentAlignment]::MiddleCenter
- #~~< cbVPNName >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- $cbVPNName = New-Object System.Windows.Forms.ComboBox
- $cbVPNName.FormattingEnabled = $true
- $cbVPNName.Location = New-Object System.Drawing.Point(74, 8)
- $cbVPNName.SelectedIndex = -1
- $cbVPNName.Size = New-Object System.Drawing.Size(200, 21)
- $cbVPNName.TabIndex = 0
- $cbVPNName.Text = ""
- $cbVPNName.add_SelectedIndexChanged({cbVPNName_changed($cbVPNName)})
- $Form1.Controls.Add($btnSplitDisable)
- $Form1.Controls.Add($btnSplitEnable)
- $Form1.Controls.Add($lblSplitTunellingStatus)
- $Form1.Controls.Add($Label1)
- $Form1.Controls.Add($cbVPNName)
- #endregion
- #region Custom Code
- $VPN = Get-VpnConnection | select name
- foreach ($vpnname in $VPN)
- {
- $cbVPNName.Items.Add($vpnname.name)
- }
- #endregion
- #region Event Loop
- function Main{
- [System.Windows.Forms.Application]::EnableVisualStyles()
- [System.Windows.Forms.Application]::Run($Form1)
- }
- #endregion
- #endregion
- #region Event Handlers
- function cbVPNName_changed($object){
- try
- {
- $selectedVPN = $cbVPNName.SelectedItem
- $status = Get-VPNConnection -name $selectedVPN
- if ($status.SplitTunneling -eq $true)
- {
- $lblSplitTunellingStatus.Text = "VPN isn't a default gateway"
- $btnSplitEnable.Enabled = $false
- $btnSplitDisable.Enabled = $true
- }
- elseif ($status.SplitTunneling -eq $false)
- {
- $lblSplitTunellingStatus.Text = "VPN is a default gateway"
- $btnSplitEnable.Enabled = $true
- $btnSplitDisable.Enabled = $false
- }
- }
- catch
- {
- [System.Windows.Forms.MessageBox]::Show("VPN connection do not exist", "Error", "OK", "Error")
- }
- }
- function btnSplitDisable_click( $object ){
- try
- {
- $selectedVPN = $cbVPNName.SelectedItem
- set-VpnConnection -name $selectedVPN -SplitTunneling $false
- $lblSplitTunellingStatus.Text = "VPN is a default gateway"
- $btnSplitDisable.Enabled = $false
- $btnSplitEnable.Enabled = $true
- }
- catch
- {
- [System.Windows.Forms.MessageBox]::Show("VPN connection do not exist", "Error", "OK", "Error")
- }
- }
- function btnSplitEnable_click( $object ){
- try
- {
- $selectedVPN = $cbVPNName.SelectedItem
- set-VpnConnection -name $selectedVPN -SplitTunneling $true
- $lblSplitTunellingStatus.Text = "VPN isn't a default gateway"
- $btnSplitEnable.Enabled = $false
- $btnSplitDisable.Enabled = $true
- }
- catch
- {
- [System.Windows.Forms.MessageBox]::Show("VPN connection do not exist", "Error", "OK", "Error")
- }
- }
- Main # This call must remain below all other event functions
- #endregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement