Bonjour
Le but de mon script est de télécharger des logiciels que je selectionne dans une interface et de les placer dans un répertoire particulier.
Le problème que je rencontre est que je voudrais afficher des informations pendant le téléchargement.
Sauf que je ne sais pas comment faire pour que mon process laisse la main à l'interface graphique.
Si quelqu'un à une solution?
Voici mon code pour l'interface graphique
Voici le code de mon scriptCode:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Téléchargement ESET" Height="250" Width="525" ResizeMode="NoResize"> <Grid> <Rectangle Fill="#FFF4F4F5" HorizontalAlignment="Left" Height="100" Margin="267,46,0,0" Stroke="Black" VerticalAlignment="Top" Width="220"/> <Rectangle Fill="#FFF4F4F5" HorizontalAlignment="Left" Height="100" Margin="33,46,0,0" Stroke="Black" VerticalAlignment="Top" Width="220"/> <CheckBox Name="chk_EraAllInOne" Content="All In One" HorizontalAlignment="Left" Margin="51,56,0,0" VerticalAlignment="Top"/> <CheckBox Name="chk_EraRemoteTool" Content="Remote Deployement Tool" HorizontalAlignment="Left" Margin="51,76,0,0" VerticalAlignment="Top" /> <CheckBox Name="chk_EraAgentX86" Content="Agent x86" HorizontalAlignment="Left" Margin="51,96,0,0" VerticalAlignment="Top"/> <CheckBox Name="chk_EraAgentX64" Content="Agent x64" HorizontalAlignment="Left" Margin="51,116,0,0" VerticalAlignment="Top"/> <CheckBox Name="chk_EEAx86" Content="Eset Endpoint Antivirus x86" HorizontalAlignment="Left" Margin="280,56,0,0" VerticalAlignment="Top"/> <CheckBox Name="chk_EEAx64" Content="Eset Endpoint Antivirus x64" HorizontalAlignment="Left" Margin="280,76,0,0" VerticalAlignment="Top"/> <CheckBox Name="chk_EFSx64" Content="Eset File Server x64" HorizontalAlignment="Left" Margin="280,96,0,0" VerticalAlignment="Top"/> <Label Name="lab_ERA" Content="Serveur ERA" HorizontalAlignment="Left" Margin="33,20,0,0" VerticalAlignment="Top"/> <Label Name="lab_Eset" Content="ESET Protection" HorizontalAlignment="Left" Margin="267,20,0,0" VerticalAlignment="Top"/> <Button Name="but_Download" Content="Téléchargement" HorizontalAlignment="Left" Margin="33,162,0,0" VerticalAlignment="Top" Width="100"/> <ProgressBar Name="pb_Download" HorizontalAlignment="Left" Height="20" Margin="153,162,0,0" VerticalAlignment="Top" Width="334"/> <TextBox Name="txt_Download" HorizontalAlignment="Left" Height="15" Margin="153,188,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="334" FontSize="8" BorderBrush="White"/> </Grid> </Window>
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
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 # Déclaration de variable $FOLDERROOT = 'C:\APPS\' $FOLDERESET = "$($FOLDERROOT)ESET\" $FOLDERESETAGENT = "$($FOLDERESET)Agents\" $FOLDEREEA = "$($FOLDERESET)EEA\" $FOLDEREFSW = "$($FOLDERESET)EFSW\" # Import Framework assemblies try{ Add-Type -AssemblyName PresentationCore,PresentationFramework,WindowsBase,system.windows.forms } catch { Throw "Failed to load Windows Presentation Framework assemblies." } # Import xaml file [xml]$Global:xmlWPF = Get-Content -Path '.\GUI.xaml' -Encoding UTF8 # Create UI object $Global:xamGUI = [Windows.Markup.XamlReader]::Load((new-object System.Xml.XmlNodeReader $xmlWPF)) # Create a variable for each control $xmlWPF.SelectNodes("//*[@Name]") | %{ Set-Variable -Name ($_.Name) -Value $xamGUI.FindName($_.Name) -Scope Global } #Ajout des evenements $but_Download.Add_Click({ #Get-Variable "chk*" | %{Write-Host $xamGUI.FindName($_.Name).IsChecked} Import-Module BitsTransfer -ErrorAction SilentlyContinue -ErrorVariable ModuleState # Continue only if the module is correctly imported if(!($ModuleState)){ if ($chk_EraAllInOne.IsChecked) { If (-not (Test-Path $FOLDERESET)) {New-Item -Path $FOLDERESET -ItemType Directory -Force} #Serveur x64 $txt_Download.text = "Téléchargement du package serveur All In One en cours..." Start-Sleep -s 1 Start-BitsTransfer -Source "https://download.eset.com/com/eset/apps/business/era/allinone/latest/x64.zip" -Destination "$($FOLDERESET)x64.zip" } if ($chk_EraRemoteTool.IsChecked) { If (-not (Test-Path $FOLDERESET)) {New-Item -Path $FOLDERESET -ItemType Directory -Force} #Outils de déploiement $txt_Download.text = "Téléchargement du zip ERA Remote Tool en cours..." Start-Sleep -s 5 Start-BitsTransfer -Source "https://download.eset.com/com/eset/apps/business/era/tools/rd/latest/remote-deployment-tool.zip" -Destination "$($FOLDERESET)remote-deployment-tool.zip" } if ($chk_EraAgentX86.IsChecked) { If (-not (Test-Path $FOLDERESETAGENT)) {New-Item -Path $FOLDERESETAGENT -ItemType Directory -Force} #Agent x86 $txt_Download.text = "Téléchargement du package Agent x86 en cours..." Start-Sleep -s 1 Start-BitsTransfer -Source "https://download.eset.com/com/eset/apps/business/era/agent/latest/agent_x86.msi" -Destination "$($FOLDERESETAGENT)agent_x86.msi" } if ($chk_EraAgentX64.IsChecked) { If (-not (Test-Path $FOLDERESETAGENT)) {New-Item -Path $FOLDERESETAGENT -ItemType Directory -Force} #Agent x64 $txt_Download.text = "Téléchargement du package Agent x64 en cours..." Start-Sleep -s 1 Start-BitsTransfer -Source "https://download.eset.com/com/eset/apps/business/era/agent/latest/agent_x64.msi" -Destination "$($FOLDERESETAGENT)agent_x64.msi" } if ($chk_EEAx86.IsChecked) { If (-not (Test-Path $FOLDEREEA)) {New-Item -Path $FOLDEREEA -ItemType Directory -Force} #EEA 32bits $txt_Download.text = "Téléchargement du package EEA x86 en cours..." Start-Sleep -s 1 Start-BitsTransfer -Source "https://download.eset.com/com/eset/apps/business/eea/windows/latest/eea_nt32_fra.msi" -Destination "$($FOLDEREEA)eea_nt32_fra.msi" } if ($chk_EEAx64.IsChecked) { If (-not (Test-Path $FOLDEREEA)) {New-Item -Path $FOLDEREEA -ItemType Directory -Force} #EEA 64bits $txt_Download.text = "Téléchargement du package EEA x64 en cours..." Start-Sleep -s 1 Start-BitsTransfer -Source "https://download.eset.com/com/eset/apps/business/eea/windows/latest/eea_nt64_fra.msi" -Destination "$($FOLDEREEA)eea_nt64_fra.msi" } if ($chk_EFSx64.IsChecked) { If (-not (Test-Path $FOLDEREFSW)) {New-Item -Path $FOLDEREFSW -ItemType Directory -Force} #EFSW 64bits $txt_Download.text = "Téléchargement du package EFS x64 en cours..." Start-Sleep -s 1 Start-BitsTransfer -Source "https://download.eset.com/com/eset/apps/business/efs/windows/latest/efsw_nt64_fra.msi" -Destination "$($FOLDEREFSW)efsw_nt64_fra.msi" } #New-SmbShare -Path "C:\APPS" -Name "APPS$" -FullAccess "Tout le monde" } }) # Display UI object $xamGUI.ShowDialog() #| out-null