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
| [void][Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')
[void][Reflection.Assembly]::LoadWithPartialname("System.Drawing")
[void][Reflection.Assembly]::LoadWithPartialname("System.Single")
$label_principal = New-Object System.Windows.Forms.Label
$label_txtBox = New-Object System.Windows.Forms.Label
$label_valid = New-Object System.Windows.Forms.Label
$groupBox1 = New-Object System.Windows.Forms.Groupbox
$groupBox2 = New-Object System.Windows.Forms.Groupbox
$button_grpBox1 = New-Object System.Windows.Forms.Button
$button_grpBox2 = New-Object System.Windows.Forms.Button
$textBox1 = New-Object System.Windows.Forms.TextBox
# Label de titre
#$label_principal.AutoSize = $true;
#$label_principal.Size = New-Object System.Drawing.Font.Size(18)
$label_principal.Location = New-Object System.Drawing.Point(10, 10)
$label_principal.Name = 'label_principal'
$label_principal.Text = 'Recherche de logiciel'
# Rechercher tous les logiciels
# groupBox1
$groupBox1.Size = New-Object System.Drawing.Size(400, 100)
$groupBox1.Text = "Rechercher tous les logiciels intallés"
$groupBox1.Location = New-Object System.Drawing.Point(35, 40)
#$groupBox1.DataBindings.DefaultDataSourceUpdateMode = [System.Windows.Forms.DataSourceUpdateMode]::OnValidation
$groupBox1.TabStop = $False
$groupBox1.Name = "groupBox1"
# bouton dans groupBox1
$button_grpBox1.Name = "button_grpBox"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 150
$System_Drawing_Size.Height = 30
$button_grpBox1.Size = $System_Drawing_Size
$button_grpBox1.Text = "Rechercher"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 120
$System_Drawing_Point.Y = 30
$button_grpBox1.Location = $System_Drawing_Point
$groupBox1.Controls.Add($button_grpBox1)
# Lors d'un clique sur le bouton "Rechercher"
$button_grpBox1.Add_Click({
$word = new-object -com word.application
$word.visible = $true
$doc = $word.documents.add()
$texte = gp HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Format-List DisplayName, DisplayVersion, Publisher | out-string -width 120
$doc.content.text = $texte
$doc.content.font.name = "Calibri"
$doc.content.font.size = 10
# $env:computername définit le nom de l'ordinateur local (ne fonctionne qu'en local)
$doc.saveas([ref]"D:\Controle logiciel sur $env:computername.docx")
$label_valid.Text = 'Enregistrer dans D:\Controle logiciel sur NomDuPC'
})
# Label de confirmation d'enregistrement du fichier (A placer après l'événement Add_Click)
$label_valid.AutoSize = $true;
$label_principal.Size = New-Object System.Drawing.Size(70, 180)
$label_valid.Location = New-Object System.Drawing.Point(70, 70)
$label_valid.Name = 'label_valid'
$label_valid.set_ForeColor("Green")
$groupBox1.Controls.Add($label_valid)
#Rechercher par logiciel
# groupBox2
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 400
$System_Drawing_Size.Height = 200
$groupBox2.Size = $System_Drawing_Size
$groupBox2.Text = "Rechercher un logiciel en particulier"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 35
$System_Drawing_Point.Y = 150
$groupBox2.Location = $System_Drawing_Point
#$groupBox2.DataBindings.DefaultDataSourceUpdateMode = [System.Windows.Forms.DataSourceUpdateMode]::OnValidation
$groupBox2.TabStop = $False
$groupBox2.Name = "groupBox2"
# Label pour textBox1
$label_txtBox.AutoSize = $true;
$label_txtBox.Location = New-Object System.Drawing.Point(60, 60)
$label_txtBox.Name = 'label_txtBox'
$label_txtBox.Text = 'Entrez le nom du logiciel'
$groupBox2.Controls.Add($label_txtBox)
# textBox1
$textBox1.AutoSize = $true;
$textBox1.Name = "textBox1"
$textBox1.Location = New-Object System.Drawing.Point(215, 58)
$groupBox2.Controls.Add($textBox1)
# bouton dans groupBox2
$button_grpBox2.Name = "button_grpBox2"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 150
$System_Drawing_Size.Height = 30
$button_grpBox2.Size = $System_Drawing_Size
$button_grpBox2.Text = "Rechercher"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 120
$System_Drawing_Point.Y = 90
$button_grpBox2.Location = $System_Drawing_Point
$groupBox2.Controls.Add($button_grpBox2)
# Lors d'un clique sur le bouton "Rechercher"
$button_grpBox2.Add_Click({
# Depuis le mot tapé dans le textBox1 on va rechercher dans le document
#Get-Childitem "D:\Controle logiciel sur $env:computername.docx" -recurse | where {$_.DisplayName -eq "$textBox1"}
# Depuis le mot tapé dans le textBox1 on va rechercher dans le registre
#gp "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*" | where {$_.DisplayName -eq "$textBox1"} | Out-File -FilePath D:\test2.txt
Get-ChildItem hklm:\software\microsoft\windows\currentversion\uninstall | ForEach-Object {Get-ItemProperty $_.pspath} | Out-File -FilePath D:\test2.txt
})
# Form
$Form1 = New-Object System.Windows.Forms.form
$Form1.ClientSize = New-Object System.Drawing.Size(475, 400)
$Form1.Controls.Add($label_principal)
$Form1.Controls.Add($groupbox1)
$Form1.Controls.Add($groupbox2)
$Form1.Name = 'Form1'
$Form1.Text = 'Recherche de logiciel'
$Form1.ShowDialog() |
Partager