Question
Fenêtre pendant le traitement d'un script
- Romain
- Auteur du sujet
- Hors Ligne
- Nouveau membre
Réduire
Plus d'informations
- Messages : 4
- Remerciements reçus 0
il y a 5 ans 6 mois #27686
par Romain
Fenêtre pendant le traitement d'un script a été créé par Romain
Bonjour
Je débute avec WindowsForm et je bloque sur un problème qui paraît simple mais que je n'arrive pas à résoudre.
J'ai une partie de mon script qui copie et colle différents dossiers.
Je voudrais afficher une fenêtre avec le message : \"Copie des éléments. Veuillez patienter...\" pendant l’exécution de cette partie du script. La fenêtre doit s'afficher automatiquement quand la copie commence et s'éteindre une fois la copie terminée sans aucune intervention.
Voici mon script :
# Chargement des assemblies
[void][System.Reflection.Assembly]::LoadWithPartialName(\"System.Windows.Forms\")
[void][System.Reflection.Assembly]::LoadWithPartialName(\"System.Drawing\")
[System.Windows.Forms.Application]::EnableVisualStyles();
$file = (get-item 'C:\Users\rcarlier\Desktop\Images\loader (1).gif')
$img = [System.Drawing.Image]::Fromfile($file);
# Creation de la form principale
$form = New-Object Windows.Forms.Form
$form.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedDialog
$form.MaximizeBox = $False
$form.MinimizeBox = $False
$form.StartPosition = \"CenterScreen\"
$form.Text = \"Script de récuperation\"
$form.Width = 375
$form.Height = 270
$form.Opacity = 0.9
#Creation de l'image
$pictureBox = new-object Windows.Forms.PictureBox
$pictureBox.Width = $img.Size.Width;
$pictureBox.Height = $img.Size.Height;
$pictureBox.Image = $img;
$pictureBox.location = New-Object System.Drawing.Point(120,80);
#Création du label
$label_prez = New-Object System.Windows.Forms.Label
$label_prez.AutoSize = $true
$label_prez.Location = New-Object System.Drawing.Point(15,40)
$label_prez.Size = New-Object System.Drawing.Size(100,100)
$label_prez.Text = \"Copie des éléments en cours. Veuillez patienter... \"
$Label1Font = New-Object System.Drawing.Font(\"Tahoma\",10,[System.Drawing.FontStyle]::Bold)
$label_prez.Font = $Label1Font
#Partie avec la copie
#OUVERTURE FENETRE AVEC MESSAGE
#Comment faire pour afficher ma fenêtre pendant la copie ?????
robocopy.exe $DistUserProfile $favoritesOutlook2Path \"*.pst\" /s /R:2 /XD \"$ExcludeFromBackup\" /log+:\"$envUserName.log\" /XD C:\$Recycle.bin
#COPIE DU BUREAU
If (-not (test-path -path $EmplacementSauvegarde\Desktop)) {New-Item -ItemType Directory -path $EmplacementSauvegarde\ -name Desktop}
robocopy.exe $DistUserProfile\Desktop $EmplacementSauvegarde\Desktop /S /E /R:2 /w:3 /log+:\"$envUserName.log\" /XD $EmplacementSauvegarde
#COPIE LES IMAGES
If (-not (test-path -path $EmplacementSauvegarde\Pictures)) {New-Item -ItemType Directory -path $EmplacementSauvegarde\ -name Pictures}
robocopy.exe $DistUserProfile\Pictures $EmplacementSauvegarde\Pictures /S /E /R:2 /w:3 /log+:\"$envUserName.log\"
#COPIE LES DOCUMENTS
If (-not (test-path -path $EmplacementSauvegarde\Documents)) {New-Item -ItemType Directory -path $EmplacementSauvegarde\ -name Documents}
robocopy.exe $DistUserProfile\Documents $EmplacementSauvegarde\Documents /S /E /R:2 /w:3 /log+:\"$envUserName.log\" /XD C:\%USERPROFILE%\Documents\My Music
#COPIE LES TELECHARGEMENTS
If (-not (test-path -path $EmplacementSauvegarde\Downloads)) {New-Item -ItemType Directory -path $EmplacementSauvegarde\ -name Downloads}
robocopy.exe $DistUserProfile\Downloads $EmplacementSauvegarde\Downloads /S /E /R:2 /w:3 /log+:\"$envUserName.log\"
#COPIE LES MUSIQUES
If (-not (test-path -path $EmplacementSauvegarde\Music)) {New-Item -ItemType Directory -path $EmplacementSauvegarde\ -name Music}
robocopy.exe $DistUserProfile\Music $EmplacementSauvegarde\Music /S /E /R:2 /w:3 /log+:\"$envUserName.log\"
#COPIE LES LIENS
If (-not (test-path -path $EmplacementSauvegarde\Links)) {New-Item -ItemType Directory -path $EmplacementSauvegarde\ -name Links}
robocopy.exe $DistUserProfile\Links $EmplacementSauvegarde\Links /S /E /R:2 /w:3 /log+:\"$envUserName.log\"
###############################################################################################################################
#FERMETURE FENETRE AVEC MESSAGE
#Ajout à la fenêtre Windowsform
$form.controls.add($pictureBox)
$form.controls.add($label_prez)
$form.ShowDialog()
Merci pour l'aide que vous m’apportez !!
Je débute avec WindowsForm et je bloque sur un problème qui paraît simple mais que je n'arrive pas à résoudre.
J'ai une partie de mon script qui copie et colle différents dossiers.
Je voudrais afficher une fenêtre avec le message : \"Copie des éléments. Veuillez patienter...\" pendant l’exécution de cette partie du script. La fenêtre doit s'afficher automatiquement quand la copie commence et s'éteindre une fois la copie terminée sans aucune intervention.
Voici mon script :
# Chargement des assemblies
[void][System.Reflection.Assembly]::LoadWithPartialName(\"System.Windows.Forms\")
[void][System.Reflection.Assembly]::LoadWithPartialName(\"System.Drawing\")
[System.Windows.Forms.Application]::EnableVisualStyles();
$file = (get-item 'C:\Users\rcarlier\Desktop\Images\loader (1).gif')
$img = [System.Drawing.Image]::Fromfile($file);
# Creation de la form principale
$form = New-Object Windows.Forms.Form
$form.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedDialog
$form.MaximizeBox = $False
$form.MinimizeBox = $False
$form.StartPosition = \"CenterScreen\"
$form.Text = \"Script de récuperation\"
$form.Width = 375
$form.Height = 270
$form.Opacity = 0.9
#Creation de l'image
$pictureBox = new-object Windows.Forms.PictureBox
$pictureBox.Width = $img.Size.Width;
$pictureBox.Height = $img.Size.Height;
$pictureBox.Image = $img;
$pictureBox.location = New-Object System.Drawing.Point(120,80);
#Création du label
$label_prez = New-Object System.Windows.Forms.Label
$label_prez.AutoSize = $true
$label_prez.Location = New-Object System.Drawing.Point(15,40)
$label_prez.Size = New-Object System.Drawing.Size(100,100)
$label_prez.Text = \"Copie des éléments en cours. Veuillez patienter... \"
$Label1Font = New-Object System.Drawing.Font(\"Tahoma\",10,[System.Drawing.FontStyle]::Bold)
$label_prez.Font = $Label1Font
#Partie avec la copie
#OUVERTURE FENETRE AVEC MESSAGE
#Comment faire pour afficher ma fenêtre pendant la copie ?????
robocopy.exe $DistUserProfile $favoritesOutlook2Path \"*.pst\" /s /R:2 /XD \"$ExcludeFromBackup\" /log+:\"$envUserName.log\" /XD C:\$Recycle.bin
#COPIE DU BUREAU
If (-not (test-path -path $EmplacementSauvegarde\Desktop)) {New-Item -ItemType Directory -path $EmplacementSauvegarde\ -name Desktop}
robocopy.exe $DistUserProfile\Desktop $EmplacementSauvegarde\Desktop /S /E /R:2 /w:3 /log+:\"$envUserName.log\" /XD $EmplacementSauvegarde
#COPIE LES IMAGES
If (-not (test-path -path $EmplacementSauvegarde\Pictures)) {New-Item -ItemType Directory -path $EmplacementSauvegarde\ -name Pictures}
robocopy.exe $DistUserProfile\Pictures $EmplacementSauvegarde\Pictures /S /E /R:2 /w:3 /log+:\"$envUserName.log\"
#COPIE LES DOCUMENTS
If (-not (test-path -path $EmplacementSauvegarde\Documents)) {New-Item -ItemType Directory -path $EmplacementSauvegarde\ -name Documents}
robocopy.exe $DistUserProfile\Documents $EmplacementSauvegarde\Documents /S /E /R:2 /w:3 /log+:\"$envUserName.log\" /XD C:\%USERPROFILE%\Documents\My Music
#COPIE LES TELECHARGEMENTS
If (-not (test-path -path $EmplacementSauvegarde\Downloads)) {New-Item -ItemType Directory -path $EmplacementSauvegarde\ -name Downloads}
robocopy.exe $DistUserProfile\Downloads $EmplacementSauvegarde\Downloads /S /E /R:2 /w:3 /log+:\"$envUserName.log\"
#COPIE LES MUSIQUES
If (-not (test-path -path $EmplacementSauvegarde\Music)) {New-Item -ItemType Directory -path $EmplacementSauvegarde\ -name Music}
robocopy.exe $DistUserProfile\Music $EmplacementSauvegarde\Music /S /E /R:2 /w:3 /log+:\"$envUserName.log\"
#COPIE LES LIENS
If (-not (test-path -path $EmplacementSauvegarde\Links)) {New-Item -ItemType Directory -path $EmplacementSauvegarde\ -name Links}
robocopy.exe $DistUserProfile\Links $EmplacementSauvegarde\Links /S /E /R:2 /w:3 /log+:\"$envUserName.log\"
###############################################################################################################################
#FERMETURE FENETRE AVEC MESSAGE
#Ajout à la fenêtre Windowsform
$form.controls.add($pictureBox)
$form.controls.add($label_prez)
$form.ShowDialog()
Merci pour l'aide que vous m’apportez !!
Pièces jointes :
Connexion ou Créer un compte pour participer à la conversation.
- Philippe
- Hors Ligne
- Modérateur
Réduire
Plus d'informations
- Messages : 1778
- Remerciements reçus 21
il y a 5 ans 6 mois #27695
par Philippe
Réponse de Philippe sur le sujet Re:Fenêtre pendant le traitement d'un script
salut HuitreBleu
il faut rajouter un évènement sur \"shown\"
quand le commande \"$form.ShowDialog()\" est executer l'évènement s'exécute
et à la fin on ferme la fenetre avec \"$form.close()\"
[code:1]# Chargement des assemblies
[void][System.Reflection.Assembly]::LoadWithPartialName(\"System.Windows.Forms\"«»)
[void][System.Reflection.Assembly]::LoadWithPartialName(\"System.Drawing\"«»)
[System.Windows.Forms.Application]::EnableVisualStyles();
$file = (get-item 'C:UsersrcarlierDesktopImagesloader (1).gif')
$img = [System.Drawing.Image]::Fromfile($file);
# Creation de la form principale
$form = New-Object Windows.Forms.Form
$form.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedDialog
$form.MaximizeBox = $False
$form.MinimizeBox = $False
$form.StartPosition = \"CenterScreen\"
$form.Text = \"Script de récuperation\"
$form.Width = 375
$form.Height = 270
$form.Opacity = 0.9
#Creation de l'image
$pictureBox = new-object Windows.Forms.PictureBox
$pictureBox.Width = $img.Size.Width;
$pictureBox.Height = $img.Size.Height;
$pictureBox.Image = $img;
$pictureBox.location = New-Object System.Drawing.Point(120,80);
#Création du label
$label_prez = New-Object System.Windows.Forms.Label
$label_prez.AutoSize = $true
$label_prez.Location = New-Object System.Drawing.Point(15,40)
$label_prez.Size = New-Object System.Drawing.Size(100,100)
$label_prez.Text = \"Copie des éléments en cours. Veuillez patienter... \"
$Label1Font = New-Object System.Drawing.Font(\"Tahoma\",10,[System.Drawing.FontStyle]::Bold)
$label_prez.Font = $Label1Font
$Form.Add_Shown({
#Partie avec la copie
#OUVERTURE FENETRE AVEC MESSAGE
#Comment faire pour afficher ma fenêtre pendant la copie ?????
robocopy.exe $DistUserProfile $favoritesOutlook2Path \"*.pst\" /s /R:2 /XD \"$ExcludeFromBackup\" /log+:\"$envUserName.log\" /XD C:$Recycle.bin
#COPIE DU BUREAU
If (-not (test-path -path $EmplacementSauvegardeDesktop)) {New-Item -ItemType Directory -path $EmplacementSauvegarde -name Desktop}
robocopy.exe $DistUserProfileDesktop $EmplacementSauvegardeDesktop /S /E /R:2 /w:3 /log+:\"$envUserName.log\" /XD $EmplacementSauvegarde
#COPIE LES IMAGES
If (-not (test-path -path $EmplacementSauvegardePictures)) {New-Item -ItemType Directory -path $EmplacementSauvegarde -name Pictures}
robocopy.exe $DistUserProfilePictures $EmplacementSauvegardePictures /S /E /R:2 /w:3 /log+:\"$envUserName.log\"
#COPIE LES DOCUMENTS
If (-not (test-path -path $EmplacementSauvegardeDocuments)) {New-Item -ItemType Directory -path $EmplacementSauvegarde -name Documents}
robocopy.exe $DistUserProfileDocuments $EmplacementSauvegardeDocuments /S /E /R:2 /w:3 /log+:\"$envUserName.log\" /XD C:%USERPROFILE%DocumentsMy Music
#COPIE LES TELECHARGEMENTS
If (-not (test-path -path $EmplacementSauvegardeDownloads)) {New-Item -ItemType Directory -path $EmplacementSauvegarde -name Downloads}
robocopy.exe $DistUserProfileDownloads $EmplacementSauvegardeDownloads /S /E /R:2 /w:3 /log+:\"$envUserName.log\"
#COPIE LES MUSIQUES
If (-not (test-path -path $EmplacementSauvegardeMusic)) {New-Item -ItemType Directory -path $EmplacementSauvegarde -name Music}
robocopy.exe $DistUserProfileMusic $EmplacementSauvegardeMusic /S /E /R:2 /w:3 /log+:\"$envUserName.log\"
#COPIE LES LIENS
If (-not (test-path -path $EmplacementSauvegardeLinks)) {New-Item -ItemType Directory -path $EmplacementSauvegarde -name Links}
robocopy.exe $DistUserProfileLinks $EmplacementSauvegardeLinks /S /E /R:2 /w:3 /log+:\"$envUserName.log\"
#################################################################################################### ###########################
#FERMETURE FENETRE AVEC MESSAGE
$form.Close()
})
#Ajout à la fenêtre Windowsform
$form.controls.add($pictureBox)
$form.controls.add($label_prez)
$form.ShowDialog()[/code:1]
il faut rajouter un évènement sur \"shown\"
quand le commande \"$form.ShowDialog()\" est executer l'évènement s'exécute
et à la fin on ferme la fenetre avec \"$form.close()\"
[code:1]# Chargement des assemblies
[void][System.Reflection.Assembly]::LoadWithPartialName(\"System.Windows.Forms\"«»)
[void][System.Reflection.Assembly]::LoadWithPartialName(\"System.Drawing\"«»)
[System.Windows.Forms.Application]::EnableVisualStyles();
$file = (get-item 'C:UsersrcarlierDesktopImagesloader (1).gif')
$img = [System.Drawing.Image]::Fromfile($file);
# Creation de la form principale
$form = New-Object Windows.Forms.Form
$form.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedDialog
$form.MaximizeBox = $False
$form.MinimizeBox = $False
$form.StartPosition = \"CenterScreen\"
$form.Text = \"Script de récuperation\"
$form.Width = 375
$form.Height = 270
$form.Opacity = 0.9
#Creation de l'image
$pictureBox = new-object Windows.Forms.PictureBox
$pictureBox.Width = $img.Size.Width;
$pictureBox.Height = $img.Size.Height;
$pictureBox.Image = $img;
$pictureBox.location = New-Object System.Drawing.Point(120,80);
#Création du label
$label_prez = New-Object System.Windows.Forms.Label
$label_prez.AutoSize = $true
$label_prez.Location = New-Object System.Drawing.Point(15,40)
$label_prez.Size = New-Object System.Drawing.Size(100,100)
$label_prez.Text = \"Copie des éléments en cours. Veuillez patienter... \"
$Label1Font = New-Object System.Drawing.Font(\"Tahoma\",10,[System.Drawing.FontStyle]::Bold)
$label_prez.Font = $Label1Font
$Form.Add_Shown({
#Partie avec la copie
#OUVERTURE FENETRE AVEC MESSAGE
#Comment faire pour afficher ma fenêtre pendant la copie ?????
robocopy.exe $DistUserProfile $favoritesOutlook2Path \"*.pst\" /s /R:2 /XD \"$ExcludeFromBackup\" /log+:\"$envUserName.log\" /XD C:$Recycle.bin
#COPIE DU BUREAU
If (-not (test-path -path $EmplacementSauvegardeDesktop)) {New-Item -ItemType Directory -path $EmplacementSauvegarde -name Desktop}
robocopy.exe $DistUserProfileDesktop $EmplacementSauvegardeDesktop /S /E /R:2 /w:3 /log+:\"$envUserName.log\" /XD $EmplacementSauvegarde
#COPIE LES IMAGES
If (-not (test-path -path $EmplacementSauvegardePictures)) {New-Item -ItemType Directory -path $EmplacementSauvegarde -name Pictures}
robocopy.exe $DistUserProfilePictures $EmplacementSauvegardePictures /S /E /R:2 /w:3 /log+:\"$envUserName.log\"
#COPIE LES DOCUMENTS
If (-not (test-path -path $EmplacementSauvegardeDocuments)) {New-Item -ItemType Directory -path $EmplacementSauvegarde -name Documents}
robocopy.exe $DistUserProfileDocuments $EmplacementSauvegardeDocuments /S /E /R:2 /w:3 /log+:\"$envUserName.log\" /XD C:%USERPROFILE%DocumentsMy Music
#COPIE LES TELECHARGEMENTS
If (-not (test-path -path $EmplacementSauvegardeDownloads)) {New-Item -ItemType Directory -path $EmplacementSauvegarde -name Downloads}
robocopy.exe $DistUserProfileDownloads $EmplacementSauvegardeDownloads /S /E /R:2 /w:3 /log+:\"$envUserName.log\"
#COPIE LES MUSIQUES
If (-not (test-path -path $EmplacementSauvegardeMusic)) {New-Item -ItemType Directory -path $EmplacementSauvegarde -name Music}
robocopy.exe $DistUserProfileMusic $EmplacementSauvegardeMusic /S /E /R:2 /w:3 /log+:\"$envUserName.log\"
#COPIE LES LIENS
If (-not (test-path -path $EmplacementSauvegardeLinks)) {New-Item -ItemType Directory -path $EmplacementSauvegarde -name Links}
robocopy.exe $DistUserProfileLinks $EmplacementSauvegardeLinks /S /E /R:2 /w:3 /log+:\"$envUserName.log\"
#################################################################################################### ###########################
#FERMETURE FENETRE AVEC MESSAGE
$form.Close()
})
#Ajout à la fenêtre Windowsform
$form.controls.add($pictureBox)
$form.controls.add($label_prez)
$form.ShowDialog()[/code:1]
Connexion ou Créer un compte pour participer à la conversation.
- Romain
- Auteur du sujet
- Hors Ligne
- Nouveau membre
Réduire
Plus d'informations
- Messages : 4
- Remerciements reçus 0
il y a 5 ans 4 mois #27903
par Romain
Réponse de Romain sur le sujet Re:Fenêtre pendant le traitement d'un script
Merci beaucoup effectivement c'est bien ça
Connexion ou Créer un compte pour participer à la conversation.
Temps de génération de la page : 0.092 secondes
- Vous êtes ici :
- Accueil
- forum
- PowerShell
- Entraide pour les débutants
- Fenêtre pendant le traitement d'un script