1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
| ################################################################################
#
# Name : C:\Temp\BindChkBx\BindChkBx\Form1.ps1
# Version : 0.1
# Author :
# Date : 19/02/2015
#
# Generated with PowerShell V4.0
# https://convertform.codeplex.com/
#
# Invocation Line : Convert-Form C:\Temp\BindChkBx\BindChkBx\Form1.Designer.cs
# Source : C:\Temp\BindChkBx\BindChkBx\Form1.Designer.cs
#
# Utilisation du DataBinding pour la gestion des combobox dynamique
#
################################################################################
function Get-ScriptDirectory
{ #Return the directory name of this script
$Invocation = (Get-Variable MyInvocation -Scope 1).Value
Split-Path $Invocation.MyCommand.Path
}
$ScriptPath = Get-ScriptDirectory
$TCPports= new-object System.Collections.ArrayList
1,22,333 |% { [void]$TCPports.Add((new-Object psobject -Property @{Port=$_.tostring()}))}
$UDPports= new-object System.Collections.ArrayList
4444,55555, |% { [void]$UDPports.Add((new-Object psobject -Property @{Port=$_.tostring()}))}
# Chargement des assemblies externes
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
$Form1 = New-Object System.Windows.Forms.Form
$cbBoxFixe = New-Object System.Windows.Forms.ComboBox
$cbBoxProtocols = New-Object System.Windows.Forms.ComboBox
$cbBoxPorts = New-Object System.Windows.Forms.ComboBox
#
# cbBoxFixe
#
$cbBoxFixe.FormattingEnabled = $true
$cbBoxFixe.Items.AddRange(@('srv1','srv2','srv3'))
$cbBoxFixe.Location = New-Object System.Drawing.Point(22, 22)
$cbBoxFixe.Name = "cbBoxFixe"
$cbBoxFixe.Size = New-Object System.Drawing.Size(150, 21)
$cbBoxFixe.TabIndex = 0
#
# cbBoxProtocols
#
$cbBoxProtocols.FormattingEnabled = $true
$cbBoxProtocols.Items.AddRange(@(
"TCP",
"UDP"))
$cbBoxProtocols.Location = New-Object System.Drawing.Point(180, 22)
$cbBoxProtocols.Name = "cbBoxProtocols"
$cbBoxProtocols.Size = New-Object System.Drawing.Size(60, 21)
$cbBoxProtocols.TabIndex = 1
$cbBoxProtocols.SelectedIndex = 0
$cbBoxPorts.DataSource = $TCPports
$cbBoxPorts.DisplayMember = "Port"
function OnSelectionChangeCommitted_cbBoxProtocols {
$cbBoxPorts.DataSource = $Null
if ($this.SelectedItem -eq 'TCP')
{ $cbBoxPorts.DataSource = $TCPports }
else
{ $cbBoxPorts.DataSource = $UDPports }
$cbBoxPorts.DisplayMember = "Port"
}
$cbBoxProtocols.Add_SelectionChangeCommitted( { OnSelectionChangeCommitted_cbBoxProtocols } )
#
# cbBoxPorts
#
$cbBoxPorts.FormattingEnabled = $true
$cbBoxPorts.Location = New-Object System.Drawing.Point(250, 22)
$cbBoxPorts.Name = "cbBoxPorts"
$cbBoxPorts.Size = New-Object System.Drawing.Size(55, 21)
$cbBoxPorts.TabIndex = 2
#
# boxButton
#
$Button = New-Object System.Windows.Forms.Button
$Button.Location = New-Object System.Drawing.Point(55, 60)
$Button.Size = New-Object System.Drawing.Size(98, 23)
$Button.Text = "Connexion"
$Button.add_Click(
{
if ($Button.Text -eq "Connexion")
{
# $label.Text = "Connexion sur le serveur :",$cbBoxFixe.SelectedItem.ToString()," avec le protocole :",$cbBoxProtocols.SelectedItem.ToString()," sur le port :", $cbBoxPorts.SelectedItem.ToString()
# $label.Text = "Connecté sur :",$cbBoxFixe.SelectedItem.ToString()
$label.Text = Get-NetAdapter -Name 'Local Area Connection'|select MediaConnectionState
$Button.Text = "Déconnexion"
$cbBoxFixe.Enabled = $false
$cbBoxProtocols.Enabled = $false
$cbBoxPorts.Enabled = $false
Start-Process openvpn -WorkingDirectory "C:\Program Files (x86)\OpenVPN\config" -ArgumentList "--config xxxxxxx.ovpn" -NoNewWindow
}
else
{
# $label.Text = "Non connecté"
$label.Text = Get-NetAdapter -Name 'Local Area Connection'|select MediaConnectionState
$Button.Text = "Connexion"
$cbBoxFixe.Enabled = $true
$cbBoxProtocols.Enabled = $true
$cbBoxPorts.Enabled = $true
Stop-Process -name openvpn
}
}
)
$Form1.Controls.Add($Button)
#
# boxTextAffichage
#
$label = New-Object System.Windows.Forms.Label
$label.Location = New-Object System.Drawing.Point(22, 95)
$label.Size = New-Object System.Drawing.Size(300, 23)
$label.Text = Get-NetAdapter -Name 'Local Area Connection'|select MediaConnectionState
#
# Form1
#
$Form1.ClientSize = New-Object System.Drawing.Size(330, 110)
$Form1.Controls.Add($cbBoxPorts)
$Form1.Controls.Add($cbBoxProtocols)
$Form1.Controls.Add($cbBoxFixe)
$Form1.Controls.Add($label)
$Form1.Name = "Form1"
$Form1.Text = "SERVEUR GUI"
function OnFormClosing_Form1{
# $this parameter is equal to the sender (object)
# $_ is equal to the parameter e (eventarg)
# The CloseReason property indicates a reason for the closure :
# if (($_).CloseReason -eq [System.Windows.Forms.CloseReason]::UserClosing)
#Sets the value indicating that the event should be canceled.
($_).Cancel= $False
}
$Form1.Add_FormClosing( { OnFormClosing_Form1} )
$Form1.Add_Shown({$Form1.Activate()})
$ModalResult=$Form1.ShowDialog()
# Libération de la Form
$Form1.Dispose() |
Partager