#Ouvre une fenêtre.
[reflection.assembly]::LoadWithPartialName("System.Windows.Forms")
$form1 = New-Object Windows.Forms.Form
$form1.text = "suppression file et redémarrage spouleur"
$form1.Size = New-Object System.Drawing.Size(400,260)
#Création d'un label (Label).
$label1 = New-Object Windows.Forms.Label
$label1.Location = New-Object Drawing.Point 35,12
$label1.Size = New-Object System.Drawing.Size(300,15)
$label1.text = "Redémarrage du spouleur d'impression"
$label2 = New-Object Windows.Forms.Label
$label2.Location = New-Object Drawing.Point 35,42
$label2.Size = New-Object System.Drawing.Size(300,15)
$label2.text = "File d'attente de l'imprimante à vider"
$label3 = New-Object Windows.Forms.Label
$label3.Location = New-Object Drawing.Point 35,72
$label3.Size = New-Object System.Drawing.Size(300,15)
$label3.text = "dossier PRINTERS à vider"
#Création d'une case à cocher (CheckBox).
$case1 = New-Object System.Windows.Forms.CheckBox
$case1.Location = New-Object Drawing.Point 20,10
$case1.Size = New-Object System.Drawing.Size(20,20)
$case1.Checked = $false
$case2 = New-Object System.Windows.Forms.CheckBox
$case2.Location = New-Object Drawing.Point 20,40
$case2.Size = New-Object System.Drawing.Size(20,20)
$case2.Checked = $false
$case3 = New-Object System.Windows.Forms.CheckBox
$case3.Location = New-Object Drawing.Point 20,70
$case3.Size = New-Object System.Drawing.Size(20,20)
$case3.Checked = $false
#Création d'un bouton valider (Button).
$bouton1 = New-Object Windows.Forms.Button
$bouton1.Location = New-Object Drawing.Point 20,180
$bouton1.Size = New-Object System.Drawing.Size(85,23)
$bouton1.text = "Valider"
$bouton1.add_click({
#Action lorsque l'on clique sur le bouton.
if ($case1.Checked -eq $true)
{net stop spooler
net start spooler }
if ($case2.Checked -eq $true)
{
$PrinterQueue = get-wmiobject -class win32_printer
$PrinterQueue.CancelAllJobs()
}
if ($case3.Checked -eq $true)
{
net stop LPDSVC
net stop spooler
remove-item C:\Windows\System32\spool\PRINTERS\*.*
net start spooler
net start LPDSVC
}
})
#Création d'un bouton Fermer (Button).
$bouton2 = New-Object Windows.Forms.Button
$bouton2.Location = New-Object Drawing.Point 120,180
$bouton2.Size = New-Object System.Drawing.Size(85,23)
$bouton2.text = "Fermer"
$bouton2.add_click({$form1.Close()})
$IMP = Get-WmiObject -class Win32_Printer
$IMP = $IMP.Name
#Liste deroulante (ComboBox).
$liste1 = New-Object System.Windows.Forms.Combobox
$liste1.Location = New-Object Drawing.Point 20,120
$liste1.Size = New-Object System.Drawing.Size(350,200)
$liste1.DropDownStyle = "DropDownList"
$liste1.Items.AddRange($IMP)
$liste1.SelectedIndex = 0
$form1.controls.add($label1)
$form1.controls.add($label2)
$form1.controls.add($label3)
$form1.controls.add($bouton1)
$form1.controls.add($bouton2)
$form1.controls.add($image1)
$form1.controls.add($case1)
$form1.controls.add($case2)
$form1.controls.add($case3)
$form1.controls.add($liste1)
#Affiche le tout.
$form1.ShowDialog()
#Fin.
Partager