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
| function Show-MessageNotePadaMoi {
param (
[string]$Message = "Attention NotePadaMoi est ouvert sur votre poste Voulez-vous le fermer ?",
[string]$Titre = "Disponibilité NotePadaMoi sur Poste",
[switch]$OKCancel,
[switch]$AbortRetryIgnore,
[switch]$YesNoCancel,
[switch]$YesNo,
[switch]$RetryCancel,
[switch]$IconErreur,
[switch]$IconQuestion,
[switch]$IconAvertissement,
[switch]$IconInformation
)
# Affecter la valeur selon le type de boutons choisis
if ($OKCancel) { $Btn = 1 }
elseif ($AbortRetryIgnore) { $Btn = 2 }
elseif ($YesNoCancel) { $Btn = 3 }
elseif ($YesNo) { $Btn = 4 }
elseif ($RetryCancel) { $Btn = 5 }
else { $Btn = 0 }
# Affecter la valeur pour l'icone
if ($IconErreur) {$Icon = 16 }
elseif ($IconQuestion) {$Icon = 32 }
elseif ($IconAvertissement) {$Icon = 48 }
elseif ($IconInformation) {$Icon = 64 }
else {$Icon = 0 }
# Charger la biblithèque d'objets graphiques Windows.Forms
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
# Afficher la boite de dialogue et renvoyer la valeur de retour (bouton appuyé)
$Reponse = [System.Windows.Forms.MessageBox]::Show($Message, $Titre , $Btn, $Icon)
Return $Reponse
}
$ProcessPath="$Env:USERPROFILE\AppData\Local\NotePadaMoi"
$NameOfProcess="NotePadaMoi"
if ($_.ProcessName -eq $NameOfProcess) {Show-MessageNotePadaMoi -Message "Attention l'application NotePadaMoi est ouverte sur votre poste, voulez-vous la fermer ?" -Titre "Disponibilité NotePadaMoi sur poste" -YesNo -IconQuestion}
if ($Reponse -eq "Yes") {
Get-Process|Where {$_.ProcessName -eq $NameOfProcess}| Foreach {$_.Kill()}
}
else {
exit
} |
Partager