Erreur syntaxe appel fonction depuis bouton
Bonjour,
J'ai un problème de syntaxe mais je ne vois ce qui cloche, même après avoir cherché sur le net...
le problème se situe lorsque le user quitte la textbox tBoxcomp (contenant un nom d'ordi) rien ne se passe et pas d'erreur affichée. Logiquement il a renseigné le nom d'un ordi et le fait de quitter la case appelle la function Testping qui doit m'afficher si le poste répond ou pas, j'ai essayé une autre syntaxe avec une function Ecrit mais pas mieux....
Code:
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
| Add-Type AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
$MainForm = New-Object System.Windows.Forms.Form
$MainForm.Text="PrinterInstaller"
$MainForm.StartPosition = "CenterScreen"
$MainForm.Width = 500
$MainForm.Height = 500
$MainForm.TopMost = $True
$MainForm.Add_Shown({$tBoxcomp.Select()})
Function Testping {
Param($Computername)
if (Test-Connection -$Computername -Quiet) {write 'ok'} else {write 'nok'}
}
Function Ecrit ($nom)
{Write-Host $nom}
$labelordi = New-Object System.Windows.Forms.Label
$labelordi.Location = New-Object System.Drawing.Point(10,20)
$labelordi.Size = New-Object System.Drawing.Size(120,20)
$labelordi.Text = 'Nom de l''ordinateur :'
$MainForm.Controls.Add($labelordi)
$tBoxcomp = New-Object System.Windows.Forms.TextBox
$tBoxcomp.Location = New-Object System.Drawing.Point(10,40)
$tBoxcomp.Size = New-Object System.Drawing.Size(100,20)
$Comp=$tBoxcomp.text
$tBoxcomp.add_Leave({Ecrit $Comp})
$tBoxcomp.add_Leave({Testping $Comp})
$MainForm.Controls.Add($tBoxcomp)
$MainForm.ShowDialog() |