-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDism-Gui-Winpe.ps1
4946 lines (4489 loc) · 248 KB
/
Dism-Gui-Winpe.ps1
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#########################################################################################################################
# Chargement des assembly externes
#########################################################################################################################
Add-Type -AssemblyName System.Windows.Forms;
Add-Type -AssemblyName System.Drawing;
#########################################################################################################################
# Bascule le Script en mode administrateur si celui-ci est un utilisateur standard
# Nous sommes obligé d'être en status administrateur, sinon la commande DISM ne fonctionnera pas !
# Note: L'UAC peut être solicité si celui-ci est activé sur l'hôte !
# Get the ID and security principal of the current user account
# Récupère l'ID et le security principal de l'utilisateur courant
#########################################################################################################################
$myWindowsID = [System.Security.Principal.WindowsIdentity]::GetCurrent();
$myWindowsPrincipal = New-Object System.Security.Principal.WindowsPrincipal($myWindowsID);
# Get the security principal for the administrator role
# Récupère le security principal pour le rôle administrateur
#
$adminRole = [System.Security.Principal.WindowsBuiltInRole]::Administrator;
# Check to see if we are currently running as an administrator
# Regarde si nous sommes déjà en mode administrateur
#
if ($myWindowsPrincipal.IsInRole($adminRole)){
# We are running as an administrator, so change the title and background colour to indicate this
# nous sommes déjà en mode administrateur, alors, on change le titre et la couleur de fond pour indiquer cela
#
$Host.UI.RawUI.WindowTitle = $myInvocation.MyCommand.Definition + "(Elevated)";
$Host.UI.RawUI.BackgroundColor = "DarkBlue";
Clear-Host;
}
else{
# We are not running as an administrator, so relaunch as administrator
# nous ne sommes pas en administrateur, donc, on relance ce script en mode administrateur
# Create a new process object that starts PowerShell
# on créé un nouveau objet processus que l'on nomme "PowerShell"
$newProcess = New-Object System.Diagnostics.ProcessStartInfo "PowerShell";
# Specify the current script path and name as a parameter with added scope and support for scripts with spaces in it's path
#
$newProcess.Arguments = "& '" + $script:MyInvocation.MyCommand.Path + "'";
# Indicate that the process should be elevated
$newProcess.Verb = "runas";
# Start the new process
[System.Diagnostics.Process]::Start($newProcess);
# Exit from the current, unelevated, process
# sort du script courant (processus utilisateur standard)
Exit;
}
#########################################################################################################################
# Variables Globales, à revoir...
# Note: il faut ajouter le terme $global:NomVar
#########################################################################################################################
#[String]$StrFolderName; # Nom du dossier de montage du fichier WIM
$global:StrFolderName; # Nom du dossier de montage du fichier WIM
#[Boolean]$WIMMounted = $false; # état du montage du fichier WIM
$global:WIMMounted = $false;
#[String]$StrMountedImageLocation; # chemin de montage du WIM
$global:StrMountedImageLocation;
#[String]$StrIndex; # index du wim à monter
$global:StrIndex; # index du wim à monter
#[String]$StrWIM; # nom du fichier WIM
$global:StrWIM; # nom du fichier WIM
[String]$StrOutput; # sortie de la console standard (redirigé)
#$global:StrOutput;
[String]$StrDISMExitCode; # valeur de sortie de la commande DISM.EXE
[Boolean]$BlnDISMCommit; # mémorise état changement du fichier WIM monté
#[String]$StrDISMArguments; # argument de la ligne de commande DISM.exe
$global:StrDISMArguments;
[String]$StrProductKey; # Clé d'activation windows
[String]$StrEdition; # type édition produit windows
[String]$StrProductCode; # code produit
[String]$StrPatchCode; # chemin code ?
[String]$StrMSPFileName; # Nom du package de mise à jour
[String]$StrCompression; # mémorise compression WIM
#FormProgress $MaFormeProgress = new FormProgress; # Pour instancier la forme FormProgress
#FormAbout MaFormAbout=new FormAbout; # pour instancier la forme FormAbout
#########################################################################################################################
# Définition d'une classe pour le stockage des méta-données présentes dans le WIM
#########################################################################################################################
class InfosWIM
{
[int]$Index_Wim; # mémorise l'index du WIM
[string]$Nom_Wim; # mémorise le nom du WIM
[string]$Description_Wim; # mémorise la description du WIM
[uint64]$Taille_Wim; # mémorise la taille du WIM
}
#########################################################################################################################
$ListInfosWimGestionMontage= New-Object System.Collections.Generic.List[InfosWIM]; # pour le menu Gestion Montage
$ListInfosWimAppliquerImage= New-Object System.Collections.Generic.List[InfosWIM]; # pour le menu Appliquer Image
$ListInfosWimExportImage= New-Object System.Collections.Generic.List[InfosWIM]; # pour le menu Export Image
#########################################################################################################################
#########################################################################################################################
# Function de recherche de la directory en cours du script lancé
#########################################################################################################################
function Get-ScriptDirectory {
#Return the directory name of this script
$Invocation = (Get-Variable MyInvocation -Scope 1).Value; # scope 1 pour l'instance du script ? à vérifier...
Split-Path $Invocation.MyCommand.Path; # récupére le chemin du dossier
}
$ScriptPath = Get-ScriptDirectory; # Permet de connaitre le dossier actuel d'où est lancé le script
#########################################################################################################################
# Fonction de remplacement concernant FolderBrowser sous WinPE
# Note: Il existe un disfonctionnement au niveau de cette fonction, il faut obligatoirement mettre la propriété ShowHelp à
# la valeur true, pour avoir un retour sur le dossier parent au nivau du contrôle.
# C'est la fonction OpenFileDialog qui est appelée, mais son utilisation est détournée (cf option de filtre *.none)
# OpenFileDialogue, nous allons récupérer le chemin du dossier sélectionné (utilisation de OpenFileBrowser)
#########################################################################################################################
function ChoixDossier {
$f = new-object Windows.Forms.OpenFileDialog
$f.InitialDirectory = pwd # pwd (print work directory), héritage de linux
$f.Filter = "foldersOnly|*.none" # on filtre que les dossiers et non les fichiers
$f.CheckFileExists = $false # ne pas vérifier le nom du fichier
$f.CheckPathExists = $false # ne pas vérifier le chemin du fichier
$f.FileName = "OpenFldrPath" # fixe le nom du fichier par défaut (qui ne sera pas utilisé)
$f.ShowHelp = $true # obligatoire en WinPE !!, sinon pas retour sur dossier parent
$f.Multiselect = $false # pas de sélection multiple
if ($F.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK){
write-host "Fonction ChoixDossier, le dossier sélectionné est: "
write-host ([System.IO.Directory]::GetParent($F.FileName).FullName)
#[void][System.Windows.Forms.MessageBox]::Show([System.IO.Directory]::GetParent($F.FileName).FullName)
}
return [System.IO.Directory]::GetParent($F.FileName).FullName
}
#########################################################################################################################
# The -STA parameter is required
# Vérifie l'appartenance du THREAD ?, à voir...
#########################################################################################################################
if ([System.Threading.Thread]::CurrentThread.GetApartmentState() -ne [System.Threading.ApartmentState]::STA ){
Throw (new-object System.Threading.ThreadStateException("Le script courant nécessite que la session Powershell soit dans le modèle de thread STA (Single Thread Apartment)."))
}
#########################################################################################################################
# Création des contrôles en mémoires pour la partie graphique
#########################################################################################################################
$FormMain = New-Object System.Windows.Forms.Form;
$menuStrip1 = New-Object System.Windows.Forms.MenuStrip;
$toolStripMenuItem1 = New-Object System.Windows.Forms.ToolStripMenuItem;
$ouvrirLogDISMToolStripMenuItem = New-Object System.Windows.Forms.ToolStripMenuItem;
$informationSurLeWIMMontéToolStripMenuItem = New-Object System.Windows.Forms.ToolStripMenuItem;
$nettoyerLeWIMToolStripMenuItem = New-Object System.Windows.Forms.ToolStripMenuItem;
$nettoyerLimageToolStripMenuItem = New-Object System.Windows.Forms.ToolStripMenuItem;
$utiliserLeModeOnlineToolStripMenuItem = New-Object System.Windows.Forms.ToolStripMenuItem;
$aProposDeToolStripMenuItem = New-Object System.Windows.Forms.ToolStripMenuItem;
$TabGestion = New-Object System.Windows.Forms.TabControl;
$GestionMontage = New-Object System.Windows.Forms.TabPage;
$TxtBoxTaille = New-Object System.Windows.Forms.TextBox;
$label13 = New-Object System.Windows.Forms.Label;
$TxtBoxDescription = New-Object System.Windows.Forms.TextBox;
$label12 = New-Object System.Windows.Forms.Label;
$TxtBoxNom = New-Object System.Windows.Forms.TextBox;
$label11 = New-Object System.Windows.Forms.Label;
$BtnOuvrirDossierMonte = New-Object System.Windows.Forms.Button;
$BtnDemonterWim = New-Object System.Windows.Forms.Button;
$BtnMonterWim = New-Object System.Windows.Forms.Button;
$LblIndex = New-Object System.Windows.Forms.Label;
$CmbBoxIndex = New-Object System.Windows.Forms.ComboBox;
$chkMountReadOnly = New-Object System.Windows.Forms.CheckBox;
$BtnChoisirDossier = New-Object System.Windows.Forms.Button;
$BtnChoisirWim = New-Object System.Windows.Forms.Button;
$TxtDossierMontage = New-Object System.Windows.Forms.TextBox;
$LblDossierMontage = New-Object System.Windows.Forms.Label;
$LblFichierWim = New-Object System.Windows.Forms.Label;
$TxtFichierWim = New-Object System.Windows.Forms.TextBox;
$GestionPilotes = New-Object System.Windows.Forms.TabPage;
$BtnAfficheTousPilotes = New-Object System.Windows.Forms.Button;
$BtnAffichePilotesWim = New-Object System.Windows.Forms.Button;
$groupBoxSupprimerPilotes = New-Object System.Windows.Forms.GroupBox;
$BtnSupprimePilote = New-Object System.Windows.Forms.Button;
$TxtBoxNomPilote = New-Object System.Windows.Forms.TextBox;
$groupBoxAjouterPilotes = New-Object System.Windows.Forms.GroupBox;
$btnAjouterPilotes = New-Object System.Windows.Forms.Button;
$LblCheminPilote = New-Object System.Windows.Forms.Label;
$BtnChoixDossierPilote = New-Object System.Windows.Forms.Button;
$TxtBoxDossierPilotes = New-Object System.Windows.Forms.TextBox;
$ChkBoxRecurse = New-Object System.Windows.Forms.CheckBox;
$ChkBoxForceUnsigned = New-Object System.Windows.Forms.CheckBox;
$GestionPackage = New-Object System.Windows.Forms.TabPage;
$BtnAffichePackagesWim = New-Object System.Windows.Forms.Button;
$groupBox2 = New-Object System.Windows.Forms.GroupBox;
$BtnSupprimePackageBis = New-Object System.Windows.Forms.Button;
$BtnSupprimePackage = New-Object System.Windows.Forms.Button;
$LblDossierPackagebis = New-Object System.Windows.Forms.Label;
$LblNomPackage = New-Object System.Windows.Forms.Label;
$TxtBoxDossierPackageBis = New-Object System.Windows.Forms.TextBox;
$TxtBoxNomPackage = New-Object System.Windows.Forms.TextBox;
$groupBox1 = New-Object System.Windows.Forms.GroupBox;
$BtnAjoutPackage = New-Object System.Windows.Forms.Button;
$BtnChoisirDossierPackage = New-Object System.Windows.Forms.Button;
$ChkBoxIgnoreVerification = New-Object System.Windows.Forms.CheckBox;
$LblDossierPackage = New-Object System.Windows.Forms.Label;
$TxtBoxDossierPackage = New-Object System.Windows.Forms.TextBox;
$GestionFeature = New-Object System.Windows.Forms.TabPage;
$label4 = New-Object System.Windows.Forms.Label;
$label3 = New-Object System.Windows.Forms.Label;
$label2 = New-Object System.Windows.Forms.Label;
$BtnDisableFeature = New-Object System.Windows.Forms.Button;
$BtnEnableFeature = New-Object System.Windows.Forms.Button;
$BtnAfficheFeatureWim = New-Object System.Windows.Forms.Button;
$ChkBoxEnablePackagePath = New-Object System.Windows.Forms.CheckBox;
$ChkBoxEnablePackageName = New-Object System.Windows.Forms.CheckBox;
$TxtBoxFolderPackage = New-Object System.Windows.Forms.TextBox;
$TxtBoxFeaturePackageName = New-Object System.Windows.Forms.TextBox;
$TxtBoxFeatureName = New-Object System.Windows.Forms.TextBox;
$ServiceEdition = New-Object System.Windows.Forms.TabPage;
$LblEdition = New-Object System.Windows.Forms.Label;
$LblProductKey = New-Object System.Windows.Forms.Label;
$BtnFixeEdition = New-Object System.Windows.Forms.Button;
$BtnFixeCleProduit = New-Object System.Windows.Forms.Button;
$BtnAfficheEditionCible = New-Object System.Windows.Forms.Button;
$BtnAfficheEditionCourante = New-Object System.Windows.Forms.Button;
$TxtBoxEdition = New-Object System.Windows.Forms.TextBox;
$TxtBoxProductKey = New-Object System.Windows.Forms.TextBox;
$ServiceUnattend = New-Object System.Windows.Forms.TabPage;
$BtnAppliqueUnattendXML = New-Object System.Windows.Forms.Button;
$BtnChoisirXMLUnattend = New-Object System.Windows.Forms.Button;
$TxtBoxFichierXMLUnattend = New-Object System.Windows.Forms.TextBox;
$LblFichierXMLUnattend = New-Object System.Windows.Forms.Label;
$ServiceApplication = New-Object System.Windows.Forms.TabPage;
$BtnVerifierPatchsApplication = New-Object System.Windows.Forms.Button;
$LblFichierMSP = New-Object System.Windows.Forms.Label;
$LblPatchCode = New-Object System.Windows.Forms.Label;
$LblCodeProduit = New-Object System.Windows.Forms.Label;
$BtnChoisirFichierMSP = New-Object System.Windows.Forms.Button;
$BtnAfficheInfosPatchsApplications = New-Object System.Windows.Forms.Button;
$BtnAfficheApplicationsPatch = New-Object System.Windows.Forms.Button;
$BtnAfficheInfosApplications = New-Object System.Windows.Forms.Button;
$btnAfficheApplication = New-Object System.Windows.Forms.Button;
$TxtBoxNomFichierMSP = New-Object System.Windows.Forms.TextBox;
$TxtBoxPatchCode = New-Object System.Windows.Forms.TextBox;
$TxtBoxCodeProduit = New-Object System.Windows.Forms.TextBox;
$CaptureImage = New-Object System.Windows.Forms.TabPage;
$label17 = New-Object System.Windows.Forms.Label;
$TxtBoxNomWIM = New-Object System.Windows.Forms.TextBox;
$LblDescriptionWIM = New-Object System.Windows.Forms.Label;
$TxtBoxCaptureDescriptionWIM = New-Object System.Windows.Forms.TextBox;
$ChkBoxCaptureVerifier = New-Object System.Windows.Forms.CheckBox;
$LblCompression = New-Object System.Windows.Forms.Label;
$LblNomFichierWIM = New-Object System.Windows.Forms.Label;
$LblDestination = New-Object System.Windows.Forms.Label;
$LblSource = New-Object System.Windows.Forms.Label;
$CmbBoxCaptureCompression = New-Object System.Windows.Forms.ComboBox;
$TxtBoxNomFichierDest = New-Object System.Windows.Forms.TextBox;
$TxtBoxCaptureDestination = New-Object System.Windows.Forms.TextBox;
$TxtBoxCaptureSource = New-Object System.Windows.Forms.TextBox;
$BtnAjouter = New-Object System.Windows.Forms.Button;
$BtnCreer = New-Object System.Windows.Forms.Button;
$ParcourirDestination = New-Object System.Windows.Forms.Button;
$BtnParcourirSource = New-Object System.Windows.Forms.Button;
$AppliqueImage = New-Object System.Windows.Forms.TabPage;
$TxtBoxAppliquerImageTaille = New-Object System.Windows.Forms.TextBox;
$label14 = New-Object System.Windows.Forms.Label;
$TxtBoxAppliquerImageDescription = New-Object System.Windows.Forms.TextBox;
$label15 = New-Object System.Windows.Forms.Label;
$TxtBoxAppliquerImageNom = New-Object System.Windows.Forms.TextBox;
$label16 = New-Object System.Windows.Forms.Label;
$ChkBoxApplyVerifier = New-Object System.Windows.Forms.CheckBox;
$label5 = New-Object System.Windows.Forms.Label;
$CmbBoxApplyIndex = New-Object System.Windows.Forms.ComboBox;
$LblDestinationBis = New-Object System.Windows.Forms.Label;
$LblSourceBis = New-Object System.Windows.Forms.Label;
$TxtBoxApplyDestination = New-Object System.Windows.Forms.TextBox;
$BtnAppliquerImage = New-Object System.Windows.Forms.Button;
$BtnApplyParcourirDestination = New-Object System.Windows.Forms.Button;
$TxtBoxApplySource = New-Object System.Windows.Forms.TextBox;
$BtnApplyParcourirSource = New-Object System.Windows.Forms.Button;
$ExportImage = New-Object System.Windows.Forms.TabPage;
$TxtBoxExportImageTaille = New-Object System.Windows.Forms.TextBox;
$LblExportImageTaille = New-Object System.Windows.Forms.Label;
$TxtBoxExportImageDescription = New-Object System.Windows.Forms.TextBox;
$LblExportImageDescription = New-Object System.Windows.Forms.Label;
$TxtBoxExportImageNom = New-Object System.Windows.Forms.TextBox;
$LblExportImageNom = New-Object System.Windows.Forms.Label;
$LblExportName = New-Object System.Windows.Forms.Label;
$TxtBoxNomFichier = New-Object System.Windows.Forms.TextBox;
$ChkBoxExportCheckIntegrity = New-Object System.Windows.Forms.CheckBox;
$ChkBoxExportWimBoot = New-Object System.Windows.Forms.CheckBox;
$ChkBoxExportBootable = New-Object System.Windows.Forms.CheckBox;
$label9 = New-Object System.Windows.Forms.Label;
$CmbBoxExportCompression = New-Object System.Windows.Forms.ComboBox;
$label6 = New-Object System.Windows.Forms.Label;
$CmbBoxExportIndex = New-Object System.Windows.Forms.ComboBox;
$LblExportDestination = New-Object System.Windows.Forms.Label;
$LblExportSource = New-Object System.Windows.Forms.Label;
$TxtBoxExportDestination = New-Object System.Windows.Forms.TextBox;
$BtnExportImage = New-Object System.Windows.Forms.Button;
$BtnExportChoisirDossier = New-Object System.Windows.Forms.Button;
$TxtBoxExportSourceFichier = New-Object System.Windows.Forms.TextBox;
$BtnExportChoisirFichier = New-Object System.Windows.Forms.Button;
$GestionLangue = New-Object System.Windows.Forms.TabPage;
$BtnAllIntrlAppliquer = New-Object System.Windows.Forms.Button;
$TxtBoxAllIntl = New-Object System.Windows.Forms.TextBox;
$label7 = New-Object System.Windows.Forms.Label;
$BtnInfosLangue = New-Object System.Windows.Forms.Button;
$ExportDriver = New-Object System.Windows.Forms.TabPage;
$BtnExportDriverOnline = New-Object System.Windows.Forms.Button;
$label8 = New-Object System.Windows.Forms.Label;
$TxtBoxExportDossierDriverOnline = New-Object System.Windows.Forms.TextBox;
$BtnExportDriverChoisirDossierOnline = New-Object System.Windows.Forms.Button;
$BtnExportDriverOffline = New-Object System.Windows.Forms.Button;
$LblExportChoisirDossier = New-Object System.Windows.Forms.Label;
$TxtBoxExportDossierDriverOffline = New-Object System.Windows.Forms.TextBox;
$BtnExportDriverChoisirDossierOffline = New-Object System.Windows.Forms.Button;
$DecoupeImage = New-Object System.Windows.Forms.TabPage;
$BtnDecoupeChoisirFichier = New-Object System.Windows.Forms.Button;
$BtnDecoupeChoisirDossier = New-Object System.Windows.Forms.Button;
$LblDecoupeDossierDestination = New-Object System.Windows.Forms.Label;
$TxtBoxDecoupeDossierDestination = New-Object System.Windows.Forms.TextBox;
$btnDecoupeImage = New-Object System.Windows.Forms.Button;
$ChkBoxDecoupeCheckIntegrity = New-Object System.Windows.Forms.CheckBox;
$LblDecoupeTailleFichier = New-Object System.Windows.Forms.Label;
$TxtBoxDecoupeTailleFichier = New-Object System.Windows.Forms.TextBox;
$LblDecoupeNomFichierSWM = New-Object System.Windows.Forms.Label;
$LblDecoupeFichierWim = New-Object System.Windows.Forms.Label;
$TxtBoxDecoupeFichierSWM = New-Object System.Windows.Forms.TextBox;
$TxtBoxDecoupeFichierWIM = New-Object System.Windows.Forms.TextBox;
$CaptureImageFfu = New-Object System.Windows.Forms.TabPage;
$LblCaptureFfu_Description = New-Object System.Windows.Forms.Label;
$TxtBoxCaptureFfu_Description = New-Object System.Windows.Forms.TextBox;
$LstBoxCaptureFfu_LectLogique = New-Object System.Windows.Forms.ListBox;
$label18 = New-Object System.Windows.Forms.Label;
$LblCaptFfu_Nom = New-Object System.Windows.Forms.Label;
$TxtBoxCaptFfu_Nom = New-Object System.Windows.Forms.TextBox;
$LblCaptFfu_IDPlateforme = New-Object System.Windows.Forms.Label;
$TxtBoxCaptFfu_IDPlateforme = New-Object System.Windows.Forms.TextBox;
$label20 = New-Object System.Windows.Forms.Label;
$LblCaptFfu_NomFichierDest = New-Object System.Windows.Forms.Label;
$LblCaptFfu_DossierDestination = New-Object System.Windows.Forms.Label;
$LblCaptFfu_LecteurPhysique = New-Object System.Windows.Forms.Label;
$CmbBoxCaptureFfu_Compression = New-Object System.Windows.Forms.ComboBox;
$TxtBoxCaptFfu_NomFichierDestination = New-Object System.Windows.Forms.TextBox;
$TxtBoxCaptFfu_DossierDestination = New-Object System.Windows.Forms.TextBox;
$TxtBoxCaptFfu_LecteurPhysique = New-Object System.Windows.Forms.TextBox;
$BtnCaptFfu_Capture = New-Object System.Windows.Forms.Button;
$BtnCaptureFfu_DossierDestination = New-Object System.Windows.Forms.Button;
$BtnCaptureFfu_ChercheLecteurLogique = New-Object System.Windows.Forms.Button;
$AppliqueImageFfu = New-Object System.Windows.Forms.TabPage;
$LstBoxAppliqueImageFfu_LecteurLogique = New-Object System.Windows.Forms.ListBox;
$LblAppliqueImageFfu_LecteurLogique = New-Object System.Windows.Forms.Label;
$label25 = New-Object System.Windows.Forms.Label;
$LblAppliqueImageFfu_FichierSource = New-Object System.Windows.Forms.Label;
$LblAppliqueImageFfu_LecteurPhysique = New-Object System.Windows.Forms.Label;
$TxtBoxAppliqueImageFfu_MotifSFUFile = New-Object System.Windows.Forms.TextBox;
$TxtBoxAppliqueImageFfu_FichierSourceFfu = New-Object System.Windows.Forms.TextBox;
$TxtBoxAppliqueImageFfu_LecteurPhysique = New-Object System.Windows.Forms.TextBox;
$BtnAppliqueImageFfu_AppliqueFfu = New-Object System.Windows.Forms.Button;
$BtnAppliqueImageFfu_ChoisirFichierFfu = New-Object System.Windows.Forms.Button;
$BtnAppliqueImageFfu_ChercherLecteurLogique = New-Object System.Windows.Forms.Button;
$DecoupeFfu = New-Object System.Windows.Forms.TabPage;
$BtnDecoupeFfu_ChoisirFichier = New-Object System.Windows.Forms.Button;
$BtnDecoupeFfu_ChoisirDossier = New-Object System.Windows.Forms.Button;
$LblDecoupeFfu_DossierDestination = New-Object System.Windows.Forms.Label;
$TxtBoxDecoupeFfu_DossierDestination = New-Object System.Windows.Forms.TextBox;
$BtnDecoupeFfu_DecoupeImage = New-Object System.Windows.Forms.Button;
$ChkBoxDecoupeFfu_CheckIntegrity = New-Object System.Windows.Forms.CheckBox;
$LblDecoupeFfu_TailleFichier = New-Object System.Windows.Forms.Label;
$TxtBoxDecoupeFfu_TailleFichier = New-Object System.Windows.Forms.TextBox;
$LblDecoupeFfu_NomFichierSFUFile = New-Object System.Windows.Forms.Label;
$LblDecoupeFfu_NomFichierFfu = New-Object System.Windows.Forms.Label;
$TxtBoxDecoupeFfu_NomFichierSFU = New-Object System.Windows.Forms.TextBox;
$TxtBoxDecoupeFfu_NomFichierFfu = New-Object System.Windows.Forms.TextBox;
$OpenFileDialogue_ChoisirWIM = New-Object System.Windows.Forms.OpenFileDialog;
$folderBrowserDialog_ChoisirDossier = New-Object System.Windows.Forms.FolderBrowserDialog;
$TxtBoxOutput = New-Object System.Windows.Forms.TextBox;
$label1 = New-Object System.Windows.Forms.Label;
$backgroundWorkerMount = New-Object System.ComponentModel.BackgroundWorker;
$backgroundWorkerDismCommand = New-Object System.ComponentModel.BackgroundWorker;
$backgroundWorkerDismount = New-Object System.ComponentModel.BackgroundWorker;
$BtnEffaceConsoleDism = New-Object System.Windows.Forms.Button;
$OpenFileDialog_ChoisirMSP = New-Object System.Windows.Forms.OpenFileDialog;
$TxtBox_DISMVersion = New-Object System.Windows.Forms.TextBox;
$label10 = New-Object System.Windows.Forms.Label;
#########################################################################################################################
# Définition des objets contrôles graphique, ainsi que les fonctions associées
#########################################################################################################################
#
# menuStrip1
#
$menuStrip1.Items.AddRange(@(
$toolStripMenuItem1))
$menuStrip1.Location = New-Object System.Drawing.Point(0, 0);
$menuStrip1.Name = "menuStrip1";
$menuStrip1.Size = New-Object System.Drawing.Size(903, 29);
$menuStrip1.TabIndex = 0;
$menuStrip1.Text = "menuStrip1";
#
# toolStripMenuItem1
#
$toolStripMenuItem1.DropDownItems.AddRange(@(
$ouvrirLogDISMToolStripMenuItem,
$informationSurLeWIMMontéToolStripMenuItem,
$nettoyerLeWIMToolStripMenuItem,
$nettoyerLimageToolStripMenuItem,
$utiliserLeModeOnlineToolStripMenuItem,
$aProposDeToolStripMenuItem))
$toolStripMenuItem1.Font = New-Object System.Drawing.Font("Segoe UI", 12);
$toolStripMenuItem1.Name = "toolStripMenuItem1";
$toolStripMenuItem1.Size = New-Object System.Drawing.Size(63, 25);
$toolStripMenuItem1.Text = "Outils";
#
# ouvrirLogDISMToolStripMenuItem
#
$ouvrirLogDISMToolStripMenuItem.Name = "ouvrirLogDISMToolStripMenuItem";
$ouvrirLogDISMToolStripMenuItem.Size = New-Object System.Drawing.Size(273, 26);
$ouvrirLogDISMToolStripMenuItem.Text = "Ouvrir le journal DISM";
#########################################################################################################################
# Permet d'ouvrir le fichier log de l'outils DISM situé dans le répertoire c:\windows\Logs\DISM\dism.log
#########################################################################################################################
function OnClick_ouvrirLogDISMToolStripMenuItem {
#[void][System.Windows.Forms.MessageBox]::Show("L'évènement ouvrirLogDISMToolStripMenuItem.Add_Click n'est pas implémenté.");
$Process = New-Object System.Diagnostics.Process; # nouveau processus
$Process.StartInfo.FileName = "notepad.exe"; # on utilise l'éditeur notepad de windows
$process.StartInfo.Arguments="$env:windir\Logs\DISM\dism.log"; # à partir du répertoire environnement windows
$Process.Start(); # exécute le processus ici notepad.exe
$Process.WaitForExit(); # attends la fin du processus
$Process.Close(); # libère l'objet processus au niveau mémoire
}
$ouvrirLogDISMToolStripMenuItem.Add_Click( { OnClick_ouvrirLogDISMToolStripMenuItem } );
#
# informationSurLeWIMMontéToolStripMenuItem
#
$informationSurLeWIMMontéToolStripMenuItem.Name = "informationSurLeWIMMontéToolStripMenuItem";
$informationSurLeWIMMontéToolStripMenuItem.Size = New-Object System.Drawing.Size(273, 26);
$informationSurLeWIMMontéToolStripMenuItem.Text = "Informations WIMs montés";
#########################################################################################################################
# Permet d'avoir un récapitulatif des WIM montés sur l'hôte
# répertoire de montage, fichier image, index, type R/W et état
#########################################################################################################################
function OnClick_informationSurLeWIMMontéToolStripMenuItem {
#[void][System.Windows.Forms.MessageBox]::Show("L'évènement informationSurLeWIMMontéToolStripMenuItem.Add_Click n'est pas implémenté.");
$StrDISMArguments = "/Get-MountedImageInfo";
$global:StrOutput="Exécution de la ligne de commande: DISM.EXE $StrDISMArguments`r`n";
$TxtBoxOutput.Text=$global:StrOutput; # Affiche le résultat dans la console GUI
$TxtBoxOutput.Refresh();
write-host 'OnClick_informationSurLeWIMMontéToolStripMenuItem, valeur actuel de $StrOutput:'$global:StrOutput;
OnDoWork_backgroundWorkerDismCommand $StrDISMArguments; # exécution de DISM en mode asynchrone
write-host 'OnClick_informationSurLeWIMMontéToolStripMenuItem, valeur après exécution de la commande DISM:'$global:StrOutput;
$TxtBoxOutput.Text=$global:StrOutput; # Affiche le résultat dans la console
$TxtBoxOutput.Refresh();
}
$informationSurLeWIMMontéToolStripMenuItem.Add_Click( { OnClick_informationSurLeWIMMontéToolStripMenuItem } );
#
# nettoyerLeWIMToolStripMenuItem
#
$nettoyerLeWIMToolStripMenuItem.Name = "nettoyerLeWIMToolStripMenuItem";
$nettoyerLeWIMToolStripMenuItem.Size = New-Object System.Drawing.Size(273, 26);
$nettoyerLeWIMToolStripMenuItem.Text = "Nettoyer le WIM";
#########################################################################################################################
# Permet de nettoyer les WIMs (fichiers périmés sur chaque lecteur)
#########################################################################################################################
function OnClick_nettoyerLeWIMToolStripMenuItem {
#[void][System.Windows.Forms.MessageBox]::Show("L'évènement nettoyerLeWIMToolStripMenuItem.Add_Click n'est pas implémenté.");
$StrDISMArguments = "/Cleanup-WIM";
$global:StrOutput="Exécution de la ligne de commande: DISM.EXE $StrDISMArguments`r`n";
$TxtBoxOutput.Text=$global:StrOutput; # Affiche le résultat dans la console GUI
$TxtBoxOutput.Refresh();
write-host 'OnClick_nettoyerLeWIMToolStripMenuItem, valeur actuel de $StrOutput:'$global:StrOutput;
OnDoWork_backgroundWorkerDismCommand $StrDISMArguments; # exécution de DISM en mode asynchrone
write-host 'OnClick_nettoyerLeWIMToolStripMenuItem, valeur après exécution de la commande DISM:'$global:StrOutput;
$TxtBoxOutput.Text=$global:StrOutput; # Affiche le résultat dans la console
$TxtBoxOutput.Refresh();
}
$nettoyerLeWIMToolStripMenuItem.Add_Click( { OnClick_nettoyerLeWIMToolStripMenuItem } );
#
# nettoyerLimageToolStripMenuItem
#
$nettoyerLimageToolStripMenuItem.Name = "nettoyerLimageToolStripMenuItem";
$nettoyerLimageToolStripMenuItem.Size = New-Object System.Drawing.Size(273, 26);
$nettoyerLimageToolStripMenuItem.Text = "Nettoyer l'image";
#########################################################################################################################
# Permet de nettoyer les WIMs (fichiers périmés sur chaque lecteur)
#########################################################################################################################
function OnClick_nettoyerLimageToolStripMenuItem {
#[void][System.Windows.Forms.MessageBox]::Show("L'évènement nettoyerLimageToolStripMenuItem.Add_Click n'est pas implémenté.");
$StrDISMArguments = "/Image:" + "`"" + $global:StrMountedImageLocation + "`"" + " /Cleanup-Image /RevertPendingActions";
write-host 'Valeur de la variable $global:StrMountedImageLocation' + $global:StrMountedImageLocation
$global:StrOutput="Exécution de la ligne de commande: DISM.EXE $StrDISMArguments`r`n";
$TxtBoxOutput.Text=$global:StrOutput; # Affiche le résultat dans la console GUI
$TxtBoxOutput.Refresh();
write-host 'OnClick_nettoyerLimageToolStripMenuItem, valeur actuel de $StrOutput:'$global:StrOutput;
OnDoWork_backgroundWorkerDismCommand $StrDISMArguments; # exécution de DISM en mode asynchrone
write-host 'OnClick_nettoyerLimageToolStripMenuItem, valeur après exécution de la commande DISM:'$global:StrOutput;
$TxtBoxOutput.Text=$global:StrOutput; # Affiche le résultat dans la console
$TxtBoxOutput.Refresh();
}
$nettoyerLimageToolStripMenuItem.Add_Click( { OnClick_nettoyerLimageToolStripMenuItem } );
#
# utiliserLeModeOnlineToolStripMenuItem
#
$utiliserLeModeOnlineToolStripMenuItem.Name = "utiliserLeModeOnlineToolStripMenuItem";
$utiliserLeModeOnlineToolStripMenuItem.Size = New-Object System.Drawing.Size(273, 26);
$utiliserLeModeOnlineToolStripMenuItem.Text = "Utiliser le mode Online";
function OnClick_utiliserLeModeOnlineToolStripMenuItem {
[void][System.Windows.Forms.MessageBox]::Show("L'évènement utiliserLeModeOnlineToolStripMenuItem.Add_Click n'est pas implémenté.");
}
$utiliserLeModeOnlineToolStripMenuItem.Add_Click( { OnClick_utiliserLeModeOnlineToolStripMenuItem } );
#
# aProposDeToolStripMenuItem
#
$aProposDeToolStripMenuItem.Name = "aProposDeToolStripMenuItem";
$aProposDeToolStripMenuItem.Size = New-Object System.Drawing.Size(273, 26);
$aProposDeToolStripMenuItem.Text = "A propos de";
function OnClick_aProposDeToolStripMenuItem {
[void][System.Windows.Forms.MessageBox]::Show("L'évènement aProposDeToolStripMenuItem.Add_Click n'est pas implémenté.");
}
$aProposDeToolStripMenuItem.Add_Click( { OnClick_aProposDeToolStripMenuItem } );
#
# TabGestion
#
$TabGestion.Controls.Add($GestionMontage);
$TabGestion.Controls.Add($GestionPilotes);
$TabGestion.Controls.Add($GestionPackage);
$TabGestion.Controls.Add($GestionFeature);
$TabGestion.Controls.Add($ServiceEdition);
$TabGestion.Controls.Add($ServiceUnattend);
$TabGestion.Controls.Add($ServiceApplication);
$TabGestion.Controls.Add($CaptureImage);
$TabGestion.Controls.Add($AppliqueImage);
$TabGestion.Controls.Add($ExportImage);
$TabGestion.Controls.Add($GestionLangue);
$TabGestion.Controls.Add($ExportDriver);
$TabGestion.Controls.Add($DecoupeImage);
$TabGestion.Controls.Add($CaptureImageFfu);
$TabGestion.Controls.Add($AppliqueImageFfu);
$TabGestion.Controls.Add($DecoupeFfu);
$TabGestion.Font = New-Object System.Drawing.Font("Microsoft Sans Serif", 12,[System.Drawing.FontStyle]::Regular,[System.Drawing.GraphicsUnit]::Point, 0);
$TabGestion.Location = New-Object System.Drawing.Point(0, 27);
$TabGestion.Name = "TabGestion";
$TabGestion.SelectedIndex = 0;
$TabGestion.Size = New-Object System.Drawing.Size(890, 290);
$TabGestion.TabIndex = 1;
#
# GestionMontage
#
$GestionMontage.Controls.Add($TxtBoxTaille);
$GestionMontage.Controls.Add($label13);
$GestionMontage.Controls.Add($TxtBoxDescription);
$GestionMontage.Controls.Add($label12);
$GestionMontage.Controls.Add($TxtBoxNom);
$GestionMontage.Controls.Add($label11);
$GestionMontage.Controls.Add($BtnOuvrirDossierMonte);
$GestionMontage.Controls.Add($BtnDemonterWim);
$GestionMontage.Controls.Add($BtnMonterWim);
$GestionMontage.Controls.Add($LblIndex);
$GestionMontage.Controls.Add($CmbBoxIndex);
$GestionMontage.Controls.Add($chkMountReadOnly);
$GestionMontage.Controls.Add($BtnChoisirDossier);
$GestionMontage.Controls.Add($BtnChoisirWim);
$GestionMontage.Controls.Add($TxtDossierMontage);
$GestionMontage.Controls.Add($LblDossierMontage);
$GestionMontage.Controls.Add($LblFichierWim);
$GestionMontage.Controls.Add($TxtFichierWim);
$GestionMontage.Font = New-Object System.Drawing.Font("Microsoft Sans Serif", 12,[System.Drawing.FontStyle]::Regular,[System.Drawing.GraphicsUnit]::Point, 0);
$GestionMontage.Location = New-Object System.Drawing.Point(4, 29);
$GestionMontage.Name = "GestionMontage";
$GestionMontage.Padding = New-Object System.Windows.Forms.Padding(3);
$GestionMontage.Size = New-Object System.Drawing.Size(882, 257);
$GestionMontage.TabIndex = 0;
$GestionMontage.Text = "Gestion Montage";
$GestionMontage.UseVisualStyleBackColor = $true;
#
# TxtBoxTaille
#
$TxtBoxTaille.Enabled = $false;
$TxtBoxTaille.Location = New-Object System.Drawing.Point(148, 178);
$TxtBoxTaille.Name = "TxtBoxTaille";
$TxtBoxTaille.Size = New-Object System.Drawing.Size(475, 26);
$TxtBoxTaille.TabIndex = 20;
#
# label13
#
$label13.AutoSize = $true;
$label13.Location = New-Object System.Drawing.Point(11, 178);
$label13.Name = "label13";
$label13.Size = New-Object System.Drawing.Size(49, 20);
$label13.TabIndex = 19;
$label13.Text = "Taille:";
#
# TxtBoxDescription
#
$TxtBoxDescription.Enabled = $false;
$TxtBoxDescription.Location = New-Object System.Drawing.Point(148, 146);
$TxtBoxDescription.Name = "TxtBoxDescription";
$TxtBoxDescription.Size = New-Object System.Drawing.Size(475, 26);
$TxtBoxDescription.TabIndex = 18;
#
# label12
#
$label12.AutoSize = $true;
$label12.Location = New-Object System.Drawing.Point(11, 149);
$label12.Name = "label12";
$label12.Size = New-Object System.Drawing.Size(93, 20);
$label12.TabIndex = 17;
$label12.Text = "Description:";
#
# TxtBoxNom
#
$TxtBoxNom.Enabled = $false;
$TxtBoxNom.Location = New-Object System.Drawing.Point(148, 114);
$TxtBoxNom.Name = "TxtBoxNom";
$TxtBoxNom.Size = New-Object System.Drawing.Size(475, 26);
$TxtBoxNom.TabIndex = 16;
#
# label11
#
$label11.AutoSize = $true;
$label11.Location = New-Object System.Drawing.Point(11, 117);
$label11.Name = "label11";
$label11.Size = New-Object System.Drawing.Size(46, 20);
$label11.TabIndex = 15;
$label11.Text = "Nom:";
#
# BtnOuvrirDossierMonte
#
$BtnOuvrirDossierMonte.Location = New-Object System.Drawing.Point(680, 158);
$BtnOuvrirDossierMonte.Name = "BtnOuvrirDossierMonte";
$BtnOuvrirDossierMonte.Size = New-Object System.Drawing.Size(168, 45);
$BtnOuvrirDossierMonte.TabIndex = 14;
$BtnOuvrirDossierMonte.Text = "Ouvrir dossier monté";
$BtnOuvrirDossierMonte.UseVisualStyleBackColor = $true;
###########################################################################################################################
# Permet de visualiser le contenu du dossier point de montage du WIM
###########################################################################################################################
function OnClick_BtnOuvrirDossierMonte {
#[void][System.Windows.Forms.MessageBox]::Show("L'évènement BtnOuvrirDossierMonte.Add_Click n'est pas implémenté.");
$Process = New-Object System.Diagnostics.Process;
$Process.StartInfo.FileName = "explorer.exe"; # on utilise l'explorer de windows
$process.StartInfo.Arguments=$global:StrFolderName; # sur le dossier (point de montage) du wim monté
$Process.Start();
$Process.WaitForExit();
$Process.Close();
}
$BtnOuvrirDossierMonte.Add_Click( { OnClick_BtnOuvrirDossierMonte } );
#
# BtnDemonterWim
#
$BtnDemonterWim.Enabled = $true;
$BtnDemonterWim.Location = New-Object System.Drawing.Point(680, 96);
$BtnDemonterWim.Name = "BtnDemonterWim";
$BtnDemonterWim.Size = New-Object System.Drawing.Size(168, 46);
$BtnDemonterWim.TabIndex = 13;
$BtnDemonterWim.Text = "Démonter WIM";
$BtnDemonterWim.UseVisualStyleBackColor = $true;
###########################################################################################################################
# Permet de démonter un WIM en fonction de son point de montage (celui-ci à était mémorisé lors du montage)
# Attention: On ne peut monter qu'une seule et une seule image à la fois !! (pensez à démonter l'ancienne)
###########################################################################################################################
function OnClick_BtnDemonterWim {
#[void][System.Windows.Forms.MessageBox]::Show("L'évènement BtnDemonterWim.Add_Click n'est pas implémenté.");
$TxtBoxOutput.Text=""; # Efface le contenu de la console gui
$global:StrOutput = ""; # Efface le contenu de la mémoire console
$result = [System.Windows.Forms.MessageBox]::Show("Voulez-vous appliquer les changements ?", "WIM monté" , 4);
if ($Result -eq "Yes"){
$BlnDISMCommit=$true; # option /commit
}
else{
$BlnDismCommit=$false; # option /discard
}
write-host("Onclick_BtnDemonterWim, Début du démontage du Wim...");
write-host 'Onclick_BtnDemonterWim, valeur de la variable $global:StrFolderName:'$global:StrFolderName;
write-host 'Onclick_BtnDemonterWim, valeur de la variable $global:BlnDismCommit:'$BlnDismCommit;
$StrDISMExitCode = "";
$Process = New-Object System.Diagnostics.Process; # nouveau processus pour la commande DISM
$Process.StartInfo.StandardOutputEncoding= [System.Text.Encoding]::GetEncoding($Host.CurrentCulture.TextInfo.OEMCodePage);
$Process.StartInfo.RedirectStandardOutput = $true; # Redirection standard de la console
$Process.StartInfo.RedirectStandardError = $true; # Idem pour le canal d'erreur
$Process.StartInfo.UseShellExecute = $false; # processus sans shell
$Process.StartInfo.CreateNoWindow = $true; # pas de fenêtre console pour ce processus
$Process.StartInfo.FileName = "DISM.EXE";
if ($BlnDismCommit -eq $true){ # gestion du flag /Commit or /Discard (DISM)
$Process.StartInfo.Arguments = "/UnMount-Wim /MountDir:`"$global:StrFolderName`" /Commit"; # /Commit
}
else{
$Process.StartInfo.Arguments = "/UnMount-Wim /MountDir:`"$global:StrFolderName`" /Discard"; # /Discard
}
Write-host "Exécution de la ligne de commande: DISM.EXE "$Process.StartInfo.Arguments.ToString();
$global:StrOutput = "Exécution de la ligne de commande: DISM.EXE "+$Process.StartInfo.Arguments.ToString();
$TxtBoxOutput.Text=$global:StrOutput;
$TxtBoxOutput.Refresh();
$Process.Start() | Out-Null; # Out-Null évite le retour de True sur la console
#write-host $Process.StandardOutput.ReadToEnd(); # affichage dans console ou dans forme, mais pas les deux en même temps
$global:StrOutput=$global:StrOutput+$Process.StandardOutput.ReadToEnd();
$Process.WaitForExit(); # attend la fin du processus
$TxtBoxOutput.Text=$global:StrOutput;
$TxtBoxOutput.Refresh();
write-host 'Onclick_BtnDemonterWim, Valeur de retour de $Process.ExitCode:'$Process.ExitCode;
if ($Process.ExitCode -eq 0){
$global:WIMMounted=$false; # le fichier wim est démonté
$global:StrMountedImageLocation=""; # fixe chemin du point de montage wim à la valeur vide
$BtnMonterWim.Enabled=$true; # désactive le bouton BtnMounterWim (1 seul Wim à la fois)
$BtnDemonterWim.Enabled=$true; # active le bouton BtnDemonterWim
}
else{
$global:WIMMounted=$false; # le wim n'est pas monté
}
write-host("Onclick_BtnDemonterWim, Fin du démontage du Wim...");
$Process.Close(); # referme le processus
}
$BtnDemonterWim.Add_Click( { OnClick_BtnDemonterWim } );
#
# BtnMonterWim
#
$BtnMonterWim.Location = New-Object System.Drawing.Point(680, 19);
$BtnMonterWim.Name = "BtnMonterWim";
$BtnMonterWim.Size = New-Object System.Drawing.Size(168, 45);
$BtnMonterWim.TabIndex = 12;
$BtnMonterWim.Text = "Monter Wim";
$BtnMonterWim.UseVisualStyleBackColor = $true;
#########################################################################################################################
# Permet de monter un fichier WIM en fonction de l'index sélectionné et du point de montage
#
#########################################################################################################################
function OnClick_BtnMonterWim {
# [void][System.Windows.Forms.MessageBox]::Show("L'évènement BtnMonterWim.Add_Click n'est pas implémenté.");
$global:StrFolderName = $TxtDossierMontage.Text; # mémorise dossier montage
$global:StrIndex = $CmbBoxIndex.Text; # idem pour l'index
$global:StrWIM = $TxtFichierWim.Text; # idem pour le nom du WIM
$global:StrOutput = "" # Efface le contenu
write-host("OnClick_BtnMonterWim, Début du montage du Wim..."); # petit message dans powershell (début de la fonction montage du wim)
write-host 'Onclick_BtnMonterWim, valeur de la variable $global:StrFolderName:'$global:StrFolderName;# affiche les variables globales
write-host 'Onclick_BtnMonterWim, valeur de la variable $global:StrIndex:'$global:StrIndex;
write-host 'Onclick_BtnMonterWim, valeur de la variable $global:StrWIM:'$global:StrWIM;
$StrDISMExitCode = "";
$Process = New-Object System.Diagnostics.Process;
$Process.StartInfo.StandardOutputEncoding= [System.Text.Encoding]::GetEncoding($Host.CurrentCulture.TextInfo.OEMCodePage);
$Process.StartInfo.RedirectStandardOutput = $true;
$Process.StartInfo.RedirectStandardError = $true;
$Process.StartInfo.UseShellExecute = $false;
$Process.StartInfo.CreateNoWindow = $true;
$Process.StartInfo.FileName = "DISM.EXE";
if ($chkMountReadOnly.Checked -eq $true){ # gestion du flag lecture seule /ReadOnly (DISM)
$Process.StartInfo.Arguments = "/Mount-Wim /WimFile:`"$global:StrWIM`" /Index:$global:StrIndex /MountDir:`"$global:StrFolderName`" /ReadOnly";
}
else{
$Process.StartInfo.Arguments = "/Mount-Wim /WimFile:`"$global:StrWIM`" /Index:$global:StrIndex /MountDir:`"$global:StrFolderName`"";
}
Write-host "OnClick_BtnMonterWim, Exécution de la ligne de commande: DISM.EXE "$Process.StartInfo.Arguments.ToString();
$global:StrOutput = "Exécution de la ligne de commande: DISM.EXE "+$Process.StartInfo.Arguments.ToString();
$TxtBoxOutput.Text=$global:StrOutput;
$TxtBoxOutput.Refresh();
$Process.Start() | Out-Null; # Out-Null évite le retour de True sur la console
#write-host $Process.StandardOutput.ReadToEnd(); # permet l'affichage des infos dans la console powershell
$global:StrOutput=$global:StrOutput+$Process.StandardOutput.ReadToEnd(); # permet l'affichage au niveau de la partie graphique
$Process.WaitForExit(); # attends la fin du processus
$TxtBoxOutput.Text=$global:StrOutput; # mise à jour du contenu du contrôle (console text dans forme graphique)
$TxtBoxOutput.Refresh(); # on rafraichit le contrôle
write-host 'Onclick_BtnMonterWim, Valeur de retour de $Process.ExitCode:'$Process.ExitCode;
if ($Process.ExitCode -eq 0){
$global:WIMMounted=$true; # le fichier wim est monté
$global:StrMountedImageLocation=$TxtDossierMontage.Text; # mémorise chemin point de montage
$BtnMonterWim.Enabled=$false; # désactive le bouton BtnMounterWim (1 seul Wim à la fois)
$BtnDemonterWim.Enabled=$true; # active le bouton BtnDemonterWim
}
else{
$global:WIMMounted=$false; # le wim n'est pas monté
}
write-host("OnClick_BtnMonterWim, Fin du montage du Wim..."); # petit message fin de montage du wim dans powershell
$Process.Close(); # referme le processus
}
$BtnMonterWim.Add_Click( { OnClick_BtnMonterWim } );
#
# LblIndex
#
$LblIndex.AutoSize = $true;
$LblIndex.Location = New-Object System.Drawing.Point(575, 3);
$LblIndex.Name = "LblIndex";
$LblIndex.Size = New-Object System.Drawing.Size(48, 20);
$LblIndex.TabIndex = 11;
$LblIndex.Text = "Index";
#
# CmbBoxIndex
#
$CmbBoxIndex.FormattingEnabled = $true;
$CmbBoxIndex.Location = New-Object System.Drawing.Point(579, 28);
$CmbBoxIndex.Name = "CmbBoxIndex";
$CmbBoxIndex.Size = New-Object System.Drawing.Size(45, 28);
$CmbBoxIndex.TabIndex = 10;
#########################################################################################################################
# Mise à jour des informations concernant le WIM dans la forme principale en fonction de l'index sélectionné
#########################################################################################################################
function OnSelectedIndexChanged_CmbBoxIndex {
#[void][System.Windows.Forms.MessageBox]::Show("L'évènement CmbBoxIndex.Add_SelectedIndexChanged n'est pas implémenté.");
write-host "CmbBoxIndex, l'index sélectionner est: "$CmbBoxIndex.selectedIndex;
$TxtBoxNom.Text = $ListInfosWimGestionMontage[$CmbBoxIndex.selectedIndex].Nom_Wim;
$TxtBoxDescription.Text = $ListInfosWimGestionMontage[$CmbBoxIndex.selectedIndex].Description_Wim;
$TxtBoxTaille.Text = $ListInfosWimGestionMontage[$CmbBoxIndex.selectedIndex].Taille_Wim;
}
$CmbBoxIndex.Add_SelectedIndexChanged( { OnSelectedIndexChanged_CmbBoxIndex } );
#
# chkMountReadOnly
#
$chkMountReadOnly.AutoSize = $true;
$chkMountReadOnly.Location = New-Object System.Drawing.Point(550, 71);
$chkMountReadOnly.Name = "chkMountReadOnly";
$chkMountReadOnly.Size = New-Object System.Drawing.Size(124, 24);
$chkMountReadOnly.TabIndex = 9;
$chkMountReadOnly.Text = "Lecture seule";
$chkMountReadOnly.UseVisualStyleBackColor = $true;
#
# BtnChoisirDossier
#
$BtnChoisirDossier.Location = New-Object System.Drawing.Point(410, 69);
$BtnChoisirDossier.Name = "BtnChoisirDossier";
$BtnChoisirDossier.Size = New-Object System.Drawing.Size(125, 26);
$BtnChoisirDossier.TabIndex = 7;
$BtnChoisirDossier.Text = "Choisir Dossier";
$BtnChoisirDossier.UseVisualStyleBackColor = $true;
#########################################################################################################################
# Permet de choisir un dossier pour le point de montage
# Révision: 26/12/2020
#########################################################################################################################
function OnClick_BtnChoisirDossier {
# [void][System.Windows.Forms.MessageBox]::Show("L'évènement BtnChoisirDossier.Add_Click n'est pas implémenté.");
# définit un objet FolderBrowser
#$FolderBrowser = New-Object System.Windows.Forms.FolderBrowserDialog -Property @{
# RootFolder='MyComputer'
# SelectedPath = 'C:\' # à partir du dossier c:\
#}
#[void]$FolderBrowser.ShowDialog(); # Affiche l'objet FolderBrowser boite de dialogue
#$TxtDossierMontage.Text=$FolderBrowser.SelectedPath; # récupère la sélection de l'utilisateur
$Result=ChoixDossier
$TxtDossierMontage.Text=$Result
}
$BtnChoisirDossier.Add_Click( { OnClick_BtnChoisirDossier } );# gestion de l'évènement sur clic bouton BtnChoisirDossier
#
# BtnChoisirWim
#
$BtnChoisirWim.Font = New-Object System.Drawing.Font("Microsoft Sans Serif", 12,[System.Drawing.FontStyle]::Regular,[System.Drawing.GraphicsUnit]::Point, 0);
$BtnChoisirWim.Location = New-Object System.Drawing.Point(410, 28);
$BtnChoisirWim.Name = "BtnChoisirWim";
$BtnChoisirWim.Size = New-Object System.Drawing.Size(125, 26);
$BtnChoisirWim.TabIndex = 6;
$BtnChoisirWim.Text = "Choisir WIM";
$BtnChoisirWim.UseVisualStyleBackColor = $true;
#########################################################################################################################
# Fonction AfficheWimInfos
# Permet d'obtenir les informations concernant le wim: nombre index, nom, description, taille
#########################################################################################################################
function AfficheWimInfos([String]$NomFichier,[String]$NomFichierWim) {
$StrWIM=$NomFichierWim; # mise à jour de la variable globale (nom fichier WIM)
$StrDISMArguments = "/Get-WimInfo /WimFile:`"$NomFichierWim`""; # ligne de commande passé à la fonction DISM
write-host 'Dans AfficheWimInfos, la variable $NomFichier à pour valeur:'$NomFichier;
write-host 'Dans AfficheWimInfos, la variable $NomFichierWim à pour valeur:'$NomFichierWim;
write-host "Dans AfficheWimInfos, Exécution de la ligne de commande: DISM.EXE $StrDISMArguments";
#$TxtBoxOutput.Text="Exécution de la ligne de commande: DISM.EXE $StrDISMArguments`r`n";# pour infos utilisateur message sysntaxe de la commande DISM
$global:StrOutput="Exécution de la ligne de commande: DISM.EXE $StrDISMArguments`r`n";
write-host 'Dans AfficheWimInfos, valeur actuel de $StrOutput:'$global:StrOutput;
OnDoWork_backgroundWorkerDismCommand $StrDISMArguments;
$TxtBoxOutput.Text=$global:StrOutput; # Affiche le résultat dans la console
$TxtBoxOutput.Refresh();
try{ # sauvegarde sur disque dans le dossier en cours du résultat
$sw = New-Object System.IO.StreamWriter($NomFichier); # dans le dossier c:\windows\system32 à corriger
$sw.WriteLine($StrOutput);
$sw.Close();
}
catch{
[void][System.Windows.Forms.MessageBox]::Show("Dans AfficheWimInfos, Erreur lors de la création du fichier (wiminfos.txt):"+$_);
}
}
#########################################################################################################################
# Lecture des informations sur le WIM depuis le fichier wiminfos (du dossier de l'application)
# Révision 11/11/2020
# Nom fichier est la représentation des index sauvegardé sur disk dur
# résultat de la commande DISM /Get-WimInfo
# List<InfosWIM> ListInfosWim, tableau fortement typé qui contient les infos WIMs
#########################################################################################################################
#
function MAJListeIndex([String]$NomFichier, [System.Collections.Generic.List[InfosWIM]]$ListInfosWim) {
[string]$FileName = $NomFichier; # présent dans le dossier de l'application
[string]$LigneFic = ""; # mémorise une ligne
[string]$StrSansEspace = "";
[int]$IdxDebStr;
[string]$TailleWIm=[string]::Empty; # stockage temporaire taille wim sous forme caractères
write-host "MAJListeIndex, Nom du fichier passé en paramètre: $NomFichier";
# nom de fichier par rapport au menu dans l'application DISM-GUI
$r = New-Object System.IO.StreamReader($FileName); # déclaration objet StreamReader
$ListInfosWim.Clear(); # efface le contenu de la liste
try
{
while ($r.EndOfStream -ne $true){ # tend que pas fin de fichier
$IdxDebStr = 0; # Index de début de chaine à analyser
$LigneFic = $r.ReadLine(); # lecture d'une ligne flux StreamReader
write-host "Dans MAJListeIndex, valeur de la ligne: "$LigneFic;
#pause
$IdxDebStr = $LigneFic.IndexOf("Index"); # recherche chaine "Index :"
if ($IdxDebStr -eq 0){ # chaine trouvé si 0 sinon -1
$UnWim=[InfosWIM]::new(); # nouvelle instance de InfosWim (class)
$UnWim.Index_Wim = [System.int32]($LigneFic.Substring($IdxDebStr + 8, ($LigneFic.Length) - 8));
$LigneFic = $r.ReadLine(); # lecture nom wim
$UnWim.Nom_Wim = $LigneFic.Substring(6, ($LigneFic.Length) - 6);
write-host 'Dans MAJListeIndex, valeur de la variable $UnWim.Nom_Wim:'$UnWim.Nom_Wim;
$LigneFic = $r.ReadLine(); # lecture description
$UnWim.Description_Wim = $LigneFic.Substring(14, ($LigneFic.Length) - 14);
write-host 'Dans MAJListeIndex, valeur de la variable $UnWim.Description_Wim:'$UnWim.Description_Wim;
$LigneFic = $r.ReadLine(); # lecture taille wim
write-host 'Dans MAJListeIndex, valeur de $LigneFic: '$LigneFic;
write-host 'Dans MAJListeIndex, taille de la chaine variable $LigneFic: '$LigneFic.length;
#$StrSansEspace = $LigneFic -Replace 0x3F, "" # supprime les espaces en UTF8
#$bidule = $LigneFic.replace(0x20,"")
for ($IdxCar=0; $IdxCar -lt $LigneFic.Length; $IdxCar++)
{
if ([Char]::IsDigit($LigneFic[$IdxCar])){
$TailleWim += $LigneFic[$IdxCar];
}
}
write-host 'Dans MAJListeIndex, valeur de $TailleWim: '$TailleWim;
$UnWim.Taille_Wim=[System.Uint64]$TailleWim;
#$UnWim.Taille_Wim = [System.Uint64]($StrSansEspace.Substring(8, ($StrSansEspace.Length) - 15));# problème à résoudre
$ListInfosWim.Add($UnWim);
$TailleWim=""; # Remise à zéro du tampon mémorise la taille d'un wim
}
}
$r.Close(); # referme le fichier
}
catch{
[void][System.Windows.Forms.MessageBox]::Show("Dans MAJListeIndex, Erreur de lecture du fichier: " + $_);
}
}
#########################################################################################################################