-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheasyFPManager_V0.0.1.ps1
More file actions
1340 lines (1192 loc) · 61.4 KB
/
easyFPManager_V0.0.1.ps1
File metadata and controls
1340 lines (1192 loc) · 61.4 KB
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
#Requires -Version 5.1
#Requires -RunAsAdministrator
# PS2EXE OPTIMIERUNGEN - KRITISCH FÜR GUI-EXE
$ProgressPreference = 'SilentlyContinue' # Verhindert blinkende Progress-Fenster bei -noConsole
<#
.SYNOPSIS
Easy Folder Permissions Manager (easyFPFM) V0.0.1
.DESCRIPTION
PowerShell Script mit WPF GUI zur Verwaltung von Ordnerberechtigungen
- Anzeige aktueller Berechtigungen
- Hinzufügen von Benutzern mit spezifischen Rechten
- Unterstützung für Hauptordner, Unterordner oder beide
- Automatische Report-Erstellung bei Änderungen
.AUTHOR
PhinIT Development
.VERSION
0.0.1
.NOTES
WICHTIG FÜR EXE-KONVERTIERUNG MIT PS2EXE:
- Alle Debug-Meldungen werden AUSSCHLIESSLICH in die Log-Datei geschrieben
- Keine Write-Host, Write-Error oder Write-Warning Ausgaben in der Shell!
- Debug-Logfile: %USERPROFILE%\Documents\FolderPermissions_Reports\Debug.log
- $ProgressPreference = 'SilentlyContinue' am Anfang (verhindert Progress-Fenster)
- Visual Styles VOR GUI-Erstellung aktiviert
- ShowDialog() mit [VOID] versehen (verhindert "False" MessageBox)
- UTF8-Encoding für deutsche Umlaute
KOMPILIERUNG:
ps2exe .\easyFPManager_V0.0.1.ps1 .\easyFPManager.exe -noConsole -STA -x64 `
-iconFile .\icon.ico -title "Easy Folder Permissions Manager" `
-version "0.0.1.0" -company "PhinIT" -copyright "© 2025 Andreas Hepp"
#>
# PS2EXE: Visual Styles MÜSSEN VOR allen GUI-Objekten aktiviert werden!
[System.Windows.Forms.Application]::EnableVisualStyles()
# Assemblies laden (Out-Null verhindert MessageBoxen bei -noConsole)
Add-Type -AssemblyName PresentationFramework | Out-Null
Add-Type -AssemblyName PresentationCore | Out-Null
Add-Type -AssemblyName WindowsBase | Out-Null
Add-Type -AssemblyName System.Windows.Forms | Out-Null
# Globale Variablen
$Global:ReportsPath = "$env:USERPROFILE\Documents\FolderPermissions_Reports"
$Global:CurrentFolder = ""
$Global:PermissionsData = @()
# Logfile-Pfad für Debug-Informationen
$Global:LogFilePath = "$env:USERPROFILE\Documents\FolderPermissions_Reports\Debug.log"
# Logging-Funktion (nur in Datei, nicht in Shell)
function Write-LogEntry {
param(
[string]$Message,
[string]$Level = "INFO"
)
try {
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
$logMessage = "[$timestamp] [$Level] $Message"
Add-Content -Path $Global:LogFilePath -Value $logMessage -ErrorAction SilentlyContinue
}
catch {
# Fehler beim Schreiben ins Log werden ignoriert
}
}
# Report-Ordner erstellen falls nicht vorhanden
if (-not (Test-Path $Global:ReportsPath)) {
New-Item -Path $Global:ReportsPath -ItemType Directory -Force | Out-Null
}
# Erweiterte Funktionen
function Remove-FolderPermission {
param(
[string]$FolderPath,
[string]$Username,
[string]$ApplyTo
)
try {
$identity = [System.Security.Principal.NTAccount]$Username
switch ($ApplyTo) {
"MainOnly" {
$acl = Get-Acl -Path $FolderPath
$acl.PurgeAccessRules($identity)
Set-Acl -Path $FolderPath -AclObject $acl
Create-PermissionReport -Action "REMOVE" -Path $FolderPath -User $Username -Rights "ALL" -ApplyTo $ApplyTo
}
"SubOnly" {
$subfolders = Get-ChildItem -Path $FolderPath -Directory -Recurse
foreach ($subfolder in $subfolders) {
$acl = Get-Acl -Path $subfolder.FullName
$acl.PurgeAccessRules($identity)
Set-Acl -Path $subfolder.FullName -AclObject $acl
}
Create-PermissionReport -Action "REMOVE" -Path $FolderPath -User $Username -Rights "ALL" -ApplyTo $ApplyTo
}
"Both" {
# Hauptordner
$acl = Get-Acl -Path $FolderPath
$acl.PurgeAccessRules($identity)
Set-Acl -Path $FolderPath -AclObject $acl
# Unterordner
$subfolders = Get-ChildItem -Path $FolderPath -Directory -Recurse
foreach ($subfolder in $subfolders) {
$acl = Get-Acl -Path $subfolder.FullName
$acl.PurgeAccessRules($identity)
Set-Acl -Path $subfolder.FullName -AclObject $acl
}
Create-PermissionReport -Action "REMOVE" -Path $FolderPath -User $Username -Rights "ALL" -ApplyTo $ApplyTo
}
}
return $true
}
catch {
[System.Windows.MessageBox]::Show("Fehler beim Entfernen der Berechtigung: $($_.Exception.Message)", "Fehler", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Error)
return $false
}
}
function Backup-FolderPermissions {
param(
[string]$FolderPath
)
try {
$timestamp = Get-Date -Format "yyyy-MM-dd_HH-mm-ss"
$backupFile = "$Global:ReportsPath\Backup_$($FolderPath.Replace(':', '').Replace('\', '_'))_$timestamp.xml"
$permissions = Get-FolderPermissions -FolderPath $FolderPath -IncludeSubfolders $true
$permissions | Export-Clixml -Path $backupFile
return $backupFile
}
catch {
[System.Windows.MessageBox]::Show("Fehler beim Erstellen des Backups: $($_.Exception.Message)", "Fehler", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Error)
return $null
}
}
function Get-FilteredPermissions {
param(
[array]$Permissions,
[string]$UserFilter = "",
[string]$RightsFilter = "",
[bool]$ShowInheritedOnly = $false
)
$filtered = $Permissions
if (-not [string]::IsNullOrEmpty($UserFilter)) {
$filtered = $filtered | Where-Object { $_.User -like "*$UserFilter*" }
}
if (-not [string]::IsNullOrEmpty($RightsFilter)) {
$filtered = $filtered | Where-Object { $_.Rights -like "*$RightsFilter*" }
}
if ($ShowInheritedOnly) {
$filtered = $filtered | Where-Object { $_.Inherited -eq $true }
}
return $filtered
}
function Get-SystemUsers {
try {
$users = @()
# Lokale Benutzer
$localUsers = Get-LocalUser -ErrorAction SilentlyContinue | Where-Object { $_.Enabled -eq $true }
foreach ($user in $localUsers) {
$users += [PSCustomObject]@{
Name = $user.Name
FullName = if ($user.FullName) { "$($user.Name) ($($user.FullName))" } else { $user.Name }
Type = "Lokaler Benutzer"
SID = $user.SID
}
}
# Lokale Gruppen
$localGroups = Get-LocalGroup -ErrorAction SilentlyContinue
foreach ($group in $localGroups) {
$users += [PSCustomObject]@{
Name = $group.Name
FullName = if ($group.Description) { "$($group.Name) ($($group.Description))" } else { $group.Name }
Type = "Lokale Gruppe"
SID = $group.SID
}
}
# Bekannte System-Accounts hinzufügen
$systemAccounts = @(
@{Name="Everyone"; FullName="Everyone (Jeder)"; Type="System-Gruppe"},
@{Name="Authenticated Users"; FullName="Authenticated Users (Authentifizierte Benutzer)"; Type="System-Gruppe"},
@{Name="SYSTEM"; FullName="SYSTEM (System)"; Type="System-Account"},
@{Name="Administrators"; FullName="Administrators (Administratoren)"; Type="Lokale Gruppe"},
@{Name="Users"; FullName="Users (Benutzer)"; Type="Lokale Gruppe"}
)
foreach ($account in $systemAccounts) {
if (-not ($users | Where-Object { $_.Name -eq $account.Name })) {
$users += [PSCustomObject]@{
Name = $account.Name
FullName = $account.FullName
Type = $account.Type
SID = ""
}
}
}
return $users | Sort-Object Type, Name
}
catch {
Write-LogEntry "Fehler beim Laden der Benutzer: $($_.Exception.Message)" "ERROR"
return @()
}
}
function Remove-SelectedPermissions {
param(
[array]$SelectedPermissions,
[string]$FolderPath
)
$successCount = 0
$errorCount = 0
$errors = @()
foreach ($permission in $SelectedPermissions) {
try {
$identity = [System.Security.Principal.NTAccount]$permission.User
$acl = Get-Acl -Path $permission.Folder
$acl.PurgeAccessRules($identity)
Set-Acl -Path $permission.Folder -AclObject $acl
$successCount++
}
catch {
$errorCount++
$errors += "$($permission.User) auf $($permission.Folder): $($_.Exception.Message)"
}
}
# Report erstellen
if ($successCount -gt 0) {
Create-PermissionReport -Action "BULK_REMOVE" -Path $FolderPath -User "Multiple ($successCount)" -Rights "Various" -ApplyTo "Selected"
}
return @{
Success = $successCount
Errors = $errorCount
ErrorDetails = $errors
}
}
function Export-PermissionsToHtml {
param(
[array]$Permissions,
[string]$FilePath
)
$html = @"
<!DOCTYPE html>
<html>
<head>
<title>Ordnerberechtigungen Report</title>
<style>
body { font-family: 'Segoe UI', Arial, sans-serif; margin: 20px; }
h1 { color: #0078D4; }
table { border-collapse: collapse; width: 100%; margin-top: 20px; }
th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }
th { background-color: #f2f2f2; font-weight: bold; }
tr:nth-child(even) { background-color: #f9f9f9; }
.inherited { color: #666; font-style: italic; }
.allow { color: #107C10; }
.deny { color: #D13438; }
</style>
</head>
<body>
<h1>Ordnerberechtigungen Report</h1>
<p>Erstellt am: $(Get-Date -Format "dd.MM.yyyy HH:mm:ss")</p>
<p>Anzahl Einträge: $($Permissions.Count)</p>
<table>
<tr>
<th>Ordner</th>
<th>Benutzer/Gruppe</th>
<th>Rechte</th>
<th>Typ</th>
<th>Vererbt</th>
</tr>
"@
foreach ($perm in $Permissions) {
$inheritedClass = if ($perm.Inherited) { "inherited" } else { "" }
$accessClass = if ($perm.AccessType -eq "Allow") { "allow" } else { "deny" }
$inheritedText = if ($perm.Inherited) { "Ja" } else { "Nein" }
$html += @"
<tr class="$inheritedClass">
<td>$($perm.Folder)</td>
<td>$($perm.User)</td>
<td>$($perm.Rights)</td>
<td class="$accessClass">$($perm.AccessType)</td>
<td>$inheritedText</td>
</tr>
"@
}
$html += @"
</table>
</body>
</html>
"@
$html | Out-File -FilePath $FilePath -Encoding UTF8
}
# Hauptfunktionen
function Get-FolderPermissions {
param(
[string]$FolderPath,
[bool]$IncludeSubfolders = $false
)
$permissions = @()
try {
if ($IncludeSubfolders) {
$folders = Get-ChildItem -Path $FolderPath -Directory -Recurse -ErrorAction SilentlyContinue
$folders = @($FolderPath) + $folders.FullName
} else {
$folders = @($FolderPath)
}
foreach ($folder in $folders) {
$acl = Get-Acl -Path $folder -ErrorAction SilentlyContinue
if ($acl) {
foreach ($access in $acl.Access) {
$permissions += [PSCustomObject]@{
Folder = $folder
User = $access.IdentityReference.Value
Rights = $access.FileSystemRights
AccessType = $access.AccessControlType
Inherited = $access.IsInherited
}
}
}
}
}
catch {
[System.Windows.MessageBox]::Show("Fehler beim Lesen der Berechtigungen: $($_.Exception.Message)", "Fehler", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Error)
}
return $permissions
}
function Add-FolderPermission {
param(
[string]$FolderPath,
[string]$Username,
[string]$Rights,
[string]$ApplyTo
)
try {
$rightsEnum = [System.Security.AccessControl.FileSystemRights]$Rights
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule($Username, $rightsEnum, "Allow")
switch ($ApplyTo) {
"MainOnly" {
$acl = Get-Acl -Path $FolderPath
$acl.SetAccessRule($accessRule)
Set-Acl -Path $FolderPath -AclObject $acl
Create-PermissionReport -Action "ADD" -Path $FolderPath -User $Username -Rights $Rights -ApplyTo $ApplyTo
}
"SubOnly" {
$subfolders = Get-ChildItem -Path $FolderPath -Directory -Recurse
foreach ($subfolder in $subfolders) {
$acl = Get-Acl -Path $subfolder.FullName
$acl.SetAccessRule($accessRule)
Set-Acl -Path $subfolder.FullName -AclObject $acl
}
Create-PermissionReport -Action "ADD" -Path $FolderPath -User $Username -Rights $Rights -ApplyTo $ApplyTo
}
"Both" {
# Hauptordner
$acl = Get-Acl -Path $FolderPath
$acl.SetAccessRule($accessRule)
Set-Acl -Path $FolderPath -AclObject $acl
# Unterordner
$subfolders = Get-ChildItem -Path $FolderPath -Directory -Recurse
foreach ($subfolder in $subfolders) {
$acl = Get-Acl -Path $subfolder.FullName
$acl.SetAccessRule($accessRule)
Set-Acl -Path $subfolder.FullName -AclObject $acl
}
Create-PermissionReport -Action "ADD" -Path $FolderPath -User $Username -Rights $Rights -ApplyTo $ApplyTo
}
}
return $true
}
catch {
[System.Windows.MessageBox]::Show("Fehler beim Hinzufügen der Berechtigung: $($_.Exception.Message)", "Fehler", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Error)
return $false
}
}
function Create-PermissionReport {
param(
[string]$Action,
[string]$Path,
[string]$User,
[string]$Rights,
[string]$ApplyTo
)
$timestamp = Get-Date -Format "yyyy-MM-dd_HH-mm-ss"
$reportFile = "$Global:ReportsPath\PermissionReport_$timestamp.txt"
$report = @"
=== FOLDER PERMISSIONS REPORT ===
Datum/Zeit: $(Get-Date -Format "dd.MM.yyyy HH:mm:ss")
Aktion: $Action
Ordner: $Path
Benutzer: $User
Rechte: $Rights
Angewendet auf: $ApplyTo
=== AKTUELLE BERECHTIGUNGEN NACH ÄNDERUNG ===
"@
# Aktuelle Berechtigungen hinzufügen
$currentPerms = Get-FolderPermissions -FolderPath $Path -IncludeSubfolders ($ApplyTo -eq "Both" -or $ApplyTo -eq "SubOnly")
foreach ($perm in $currentPerms) {
$report += "`n$($perm.Folder) | $($perm.User) | $($perm.Rights) | $($perm.AccessType)"
}
$report | Out-File -FilePath $reportFile -Encoding UTF8
}
# WPF GUI XAML - Windows 11 Design
$xaml = @"
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Easy Folder Permissions Manager V0.0.1" Height="900" Width="1700"
WindowStartupLocation="CenterScreen" ResizeMode="CanResize"
Background="#F3F3F3" FontFamily="Segoe UI" FontSize="14">
<Grid Margin="15">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<!-- Vereinfachte Styles -->
<Grid.Resources>
<Style TargetType="Button">
<Setter Property="Background" Value="#0078D4"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="FontWeight" Value="SemiBold"/>
</Style>
</Grid.Resources>
<!-- Ordner Auswahl -->
<GroupBox Header="Ordner Auswahl" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Margin="0,0,0,10">
<Grid Margin="10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBox Name="txtFolderPath" Grid.Column="0" Margin="0,0,10,0" Height="32" VerticalContentAlignment="Center"/>
<Button Name="btnBrowse" Grid.Column="1" Content="Durchsuchen" Width="110" Height="32" Margin="0,0,8,0"/>
<Button Name="btnLoadPermissions" Grid.Column="2" Content="Laden" Width="90" Height="32" Margin="0,0,8,0"/>
<Button Name="btnBackup" Grid.Column="3" Content="Backup" Width="90" Height="32" Background="#107C10"/>
</Grid>
</GroupBox>
<!-- Filter und Optionen -->
<GroupBox Header="Filter und Optionen" Grid.Row="1" Grid.Column="0" Margin="0,0,10,10">
<StackPanel Margin="10" Orientation="Vertical">
<StackPanel Orientation="Horizontal" Margin="0,0,0,8">
<CheckBox Name="chkIncludeSubfolders" Content="Unterordner einbeziehen" Margin="0,0,25,0" VerticalAlignment="Center"/>
<CheckBox Name="chkShowInheritedOnly" Content="Nur vererbte Berechtigungen" VerticalAlignment="Center"/>
</StackPanel>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Label Content="Benutzer:" Grid.Column="0" VerticalAlignment="Center" Margin="0,0,8,0"/>
<TextBox Name="txtUserFilter" Grid.Column="1" Height="28" Margin="0,0,15,0" VerticalContentAlignment="Center"/>
<Label Content="Rechte:" Grid.Column="2" VerticalAlignment="Center" Margin="0,0,8,0"/>
<TextBox Name="txtRightsFilter" Grid.Column="3" Height="28" Margin="0,0,15,0" VerticalContentAlignment="Center"/>
<Button Name="btnApplyFilter" Grid.Column="4" Content="Filter" Width="70" Height="28"/>
</Grid>
</StackPanel>
</GroupBox>
<!-- Berechtigungen Anzeige -->
<GroupBox Header="Aktuelle Berechtigungen" Grid.Row="2" Grid.Column="0" Margin="0,0,10,10">
<Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<DataGrid Name="dgPermissions" Grid.Row="0" AutoGenerateColumns="True" IsReadOnly="True"
GridLinesVisibility="Horizontal" HeadersVisibility="All" MinHeight="300"/>
<StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,8,0,0">
<TextBlock Name="txtPermissionCount" Text="Einträge: 0" VerticalAlignment="Center" Margin="0,0,15,0" Foreground="#666"/>
<Button Name="btnRemoveSelected" Content="Entfernen" Width="120" Height="28" Background="#D13438" IsEnabled="False"/>
</StackPanel>
</Grid>
</GroupBox>
<!-- Rechte Spalte: Benutzer verwalten und Status -->
<StackPanel Grid.Row="1" Grid.RowSpan="2" Grid.Column="1" Margin="0,0,0,10">
<!-- Benutzer hinzufügen -->
<GroupBox Header="Benutzer verwalten" Margin="0,0,0,10">
<StackPanel Margin="10">
<Grid Margin="0,0,0,8">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBox Name="txtUsername" Grid.Column="0" Height="32" Margin="0,0,8,0" VerticalContentAlignment="Center"
ToolTip="Windows-Benutzername oder Gruppe eingeben"/>
<Button Name="btnBrowseUser" Grid.Column="1" Content="..." Width="32" Height="32" ToolTip="Benutzer auswählen"/>
</Grid>
<ComboBox Name="cmbRights" Height="32" Margin="0,0,0,8" VerticalContentAlignment="Center">
<ComboBoxItem Content="Vollzugriff" Tag="FullControl"/>
<ComboBoxItem Content="Ändern" Tag="Modify"/>
<ComboBoxItem Content="Lesen+Ausführen" Tag="ReadAndExecute"/>
<ComboBoxItem Content="Nur Lesen" Tag="Read"/>
<ComboBoxItem Content="Nur Schreiben" Tag="Write"/>
</ComboBox>
<StackPanel Orientation="Vertical" Margin="0,0,0,10">
<RadioButton Name="rbMainOnly" Content="Nur Hauptordner" Margin="0,0,0,4" IsChecked="True"/>
<RadioButton Name="rbSubOnly" Content="Nur Unterordner" Margin="0,0,0,4"/>
<RadioButton Name="rbBoth" Content="Hauptordner + Unterordner" Margin="0,0,0,4"/>
</StackPanel>
<Button Name="btnAddPermission" Content="Hinzufügen" Height="32" Margin="0,0,0,5"/>
<Button Name="btnRemovePermission" Content="Entfernen" Height="32" Background="#D13438"/>
</StackPanel>
</GroupBox>
<!-- Status und Export -->
<GroupBox Header="Status und Export">
<StackPanel Margin="10">
<TextBox Name="txtStatus" Height="80" IsReadOnly="True"
VerticalScrollBarVisibility="Auto" TextWrapping="Wrap"
Background="#F9F9F9" BorderBrush="#E1E1E1" Padding="8" Margin="0,0,0,8"/>
<Button Name="btnOpenReports" Content="Reports" Height="32" Margin="0,0,0,5" Background="#107C10"/>
<Button Name="btnExportCsv" Content="CSV Export" Height="32" Background="#FF8C00"/>
</StackPanel>
</GroupBox>
</StackPanel>
<!-- Buttons -->
<StackPanel Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2" Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,10,0,0">
<Button Name="btnRefresh" Content="Aktualisieren" Width="110" Height="32" Margin="0,0,10,0" Background="#0078D4"/>
<Button Name="btnExit" Content="Beenden" Width="90" Height="32" Background="#D13438"/>
</StackPanel>
<!-- Footer -->
<Border Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="2" Background="#E8E8E8" BorderBrush="#D0D0D0" BorderThickness="0,1,0,0" Margin="0,15,0,0">
<Grid Margin="15,8">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<!-- Links: Autor und Version -->
<StackPanel Grid.Column="0" Orientation="Horizontal" VerticalAlignment="Center">
<TextBlock Text="Easy Folder Permissions Manager V0.0.1" FontWeight="SemiBold" Foreground="#333" Margin="0,0,15,0"/>
<TextBlock Text="© 2025 Andreas Hepp | PhinIT" Foreground="#666" FontSize="12"/>
</StackPanel>
<!-- Mitte: Website Link -->
<StackPanel Grid.Column="1" Orientation="Horizontal" VerticalAlignment="Center">
<TextBlock Text="Website: " Foreground="#666" FontSize="12"/>
<TextBlock Name="txtWebsiteLink" Text="www.phinit.de" Foreground="#0078D4" FontSize="12"
TextDecorations="Underline" Cursor="Hand" ToolTip="Website öffnen"/>
</StackPanel>
<!-- Rechts: System Info -->
<StackPanel Grid.Column="2" Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Right">
<TextBlock Name="txtSystemInfo" Text="Windows PowerShell" Foreground="#666" FontSize="12" Margin="0,0,10,0"/>
<TextBlock Name="txtCurrentTime" Text="" Foreground="#666" FontSize="12"/>
</StackPanel>
</Grid>
</Border>
</Grid>
</Window>
"@
# WPF Window erstellen
try {
$reader = [System.Xml.XmlReader]::Create([System.IO.StringReader]$xaml)
$window = [Windows.Markup.XamlReader]::Load($reader)
$reader.Close()
}
catch {
Write-LogEntry "Fehler beim Laden der GUI: $($_.Exception.Message)" "ERROR"
Write-LogEntry "XAML-Inhalt zur Diagnose: $xaml" "ERROR"
exit 1
}
# Controls referenzieren
$txtFolderPath = $window.FindName("txtFolderPath")
$btnBrowse = $window.FindName("btnBrowse")
$btnLoadPermissions = $window.FindName("btnLoadPermissions")
$btnBackup = $window.FindName("btnBackup")
$chkIncludeSubfolders = $window.FindName("chkIncludeSubfolders")
$chkShowInheritedOnly = $window.FindName("chkShowInheritedOnly")
$txtUserFilter = $window.FindName("txtUserFilter")
$txtRightsFilter = $window.FindName("txtRightsFilter")
$btnApplyFilter = $window.FindName("btnApplyFilter")
$dgPermissions = $window.FindName("dgPermissions")
$txtPermissionCount = $window.FindName("txtPermissionCount")
$btnRemoveSelected = $window.FindName("btnRemoveSelected")
$txtUsername = $window.FindName("txtUsername")
$btnBrowseUser = $window.FindName("btnBrowseUser")
$cmbRights = $window.FindName("cmbRights")
$rbMainOnly = $window.FindName("rbMainOnly")
$rbSubOnly = $window.FindName("rbSubOnly")
$rbBoth = $window.FindName("rbBoth")
$btnAddPermission = $window.FindName("btnAddPermission")
$btnRemovePermission = $window.FindName("btnRemovePermission")
$txtStatus = $window.FindName("txtStatus")
$btnOpenReports = $window.FindName("btnOpenReports")
$btnExportCsv = $window.FindName("btnExportCsv")
$btnRefresh = $window.FindName("btnRefresh")
$btnExit = $window.FindName("btnExit")
$txtWebsiteLink = $window.FindName("txtWebsiteLink")
$txtSystemInfo = $window.FindName("txtSystemInfo")
$txtCurrentTime = $window.FindName("txtCurrentTime")
# Validierung der Controls
$controls = @{
"txtFolderPath" = $txtFolderPath
"btnBrowse" = $btnBrowse
"btnLoadPermissions" = $btnLoadPermissions
"btnBackup" = $btnBackup
"chkIncludeSubfolders" = $chkIncludeSubfolders
"chkShowInheritedOnly" = $chkShowInheritedOnly
"txtUserFilter" = $txtUserFilter
"txtRightsFilter" = $txtRightsFilter
"btnApplyFilter" = $btnApplyFilter
"dgPermissions" = $dgPermissions
"txtPermissionCount" = $txtPermissionCount
"btnRemoveSelected" = $btnRemoveSelected
"txtUsername" = $txtUsername
"btnBrowseUser" = $btnBrowseUser
"cmbRights" = $cmbRights
"rbMainOnly" = $rbMainOnly
"rbSubOnly" = $rbSubOnly
"rbBoth" = $rbBoth
"btnAddPermission" = $btnAddPermission
"btnRemovePermission" = $btnRemovePermission
"txtStatus" = $txtStatus
"btnOpenReports" = $btnOpenReports
"btnExportCsv" = $btnExportCsv
"btnRefresh" = $btnRefresh
"btnExit" = $btnExit
"txtWebsiteLink" = $txtWebsiteLink
"txtSystemInfo" = $txtSystemInfo
"txtCurrentTime" = $txtCurrentTime
}
foreach ($controlName in $controls.Keys) {
if ($controls[$controlName] -eq $null) {
Write-LogEntry "Control '$controlName' konnte nicht gefunden werden!" "ERROR"
exit 1
}
}
# Event Handlers
$btnBrowse.Add_Click({
$folderBrowser = New-Object System.Windows.Forms.FolderBrowserDialog
$folderBrowser.Description = "Ordner für Berechtigungsverwaltung auswählen"
# PS2EXE: ShowDialog() Rückgabewert in Variable speichern (verhindert MessageBox)
$result = $folderBrowser.ShowDialog()
if ($result -eq [System.Windows.Forms.DialogResult]::OK) {
$txtFolderPath.Text = $folderBrowser.SelectedPath
$Global:CurrentFolder = $folderBrowser.SelectedPath
$txtStatus.Text = "Ordner ausgewählt: $($folderBrowser.SelectedPath)"
}
})
$btnLoadPermissions.Add_Click({
if ([string]::IsNullOrEmpty($txtFolderPath.Text)) {
[System.Windows.MessageBox]::Show("Bitte wählen Sie zuerst einen Ordner aus.", "Hinweis", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Information)
return
}
if (-not (Test-Path $txtFolderPath.Text)) {
[System.Windows.MessageBox]::Show("Der angegebene Ordner existiert nicht.", "Fehler", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Error)
return
}
$Global:CurrentFolder = $txtFolderPath.Text
$includeSubfolders = $chkIncludeSubfolders.IsChecked
$txtStatus.Text = "Lade Berechtigungen..."
$window.Cursor = [System.Windows.Input.Cursors]::Wait
try {
$Global:PermissionsData = Get-FolderPermissions -FolderPath $Global:CurrentFolder -IncludeSubfolders $includeSubfolders
# Filter anwenden falls gesetzt
$filteredData = Get-FilteredPermissions -Permissions $Global:PermissionsData -UserFilter $txtUserFilter.Text -RightsFilter $txtRightsFilter.Text -ShowInheritedOnly $chkShowInheritedOnly.IsChecked
$dgPermissions.ItemsSource = $filteredData
$txtPermissionCount.Text = "Einträge: $($filteredData.Count) von $($Global:PermissionsData.Count)"
$txtStatus.Text = "Berechtigungen erfolgreich geladen"
}
finally {
$window.Cursor = [System.Windows.Input.Cursors]::Arrow
}
})
$btnAddPermission.Add_Click({
if ([string]::IsNullOrEmpty($Global:CurrentFolder)) {
[System.Windows.MessageBox]::Show("Bitte wählen Sie zuerst einen Ordner aus und laden Sie die Berechtigungen.", "Hinweis", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Information)
return
}
if ([string]::IsNullOrEmpty($txtUsername.Text)) {
[System.Windows.MessageBox]::Show("Bitte geben Sie einen Benutzernamen ein.", "Hinweis", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Information)
return
}
if ($cmbRights.SelectedItem -eq $null) {
[System.Windows.MessageBox]::Show("Bitte wählen Sie die Rechte aus.", "Hinweis", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Information)
return
}
$username = $txtUsername.Text
$rights = $cmbRights.SelectedItem.Tag
$applyTo = "MainOnly"
if ($rbSubOnly.IsChecked) { $applyTo = "SubOnly" }
elseif ($rbBoth.IsChecked) { $applyTo = "Both" }
$txtStatus.Text = "Füge Berechtigung hinzu..."
$window.Cursor = [System.Windows.Input.Cursors]::Wait
try {
$success = Add-FolderPermission -FolderPath $Global:CurrentFolder -Username $username -Rights $rights -ApplyTo $applyTo
if ($success) {
$txtStatus.Text = "Berechtigung erfolgreich hinzugefügt für: $username ($rights) - $applyTo"
$txtUsername.Text = ""
$cmbRights.SelectedIndex = -1
# Berechtigungen neu laden
$includeSubfolders = $chkIncludeSubfolders.IsChecked
$Global:PermissionsData = Get-FolderPermissions -FolderPath $Global:CurrentFolder -IncludeSubfolders $includeSubfolders
$filteredData = Get-FilteredPermissions -Permissions $Global:PermissionsData -UserFilter $txtUserFilter.Text -RightsFilter $txtRightsFilter.Text -ShowInheritedOnly $chkShowInheritedOnly.IsChecked
$dgPermissions.ItemsSource = $filteredData
$txtPermissionCount.Text = "Einträge: $($filteredData.Count) von $($Global:PermissionsData.Count)"
}
}
finally {
$window.Cursor = [System.Windows.Input.Cursors]::Arrow
}
})
$btnOpenReports.Add_Click({
if (Test-Path $Global:ReportsPath) {
Start-Process explorer.exe -ArgumentList $Global:ReportsPath
} else {
[System.Windows.MessageBox]::Show("Reports-Ordner wurde noch nicht erstellt.", "Hinweis", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Information)
}
})
$btnRefresh.Add_Click({
if (-not [string]::IsNullOrEmpty($Global:CurrentFolder)) {
$txtStatus.Text = "Aktualisiere Berechtigungen..."
$window.Cursor = [System.Windows.Input.Cursors]::Wait
try {
$includeSubfolders = $chkIncludeSubfolders.IsChecked
$Global:PermissionsData = Get-FolderPermissions -FolderPath $Global:CurrentFolder -IncludeSubfolders $includeSubfolders
$filteredData = Get-FilteredPermissions -Permissions $Global:PermissionsData -UserFilter $txtUserFilter.Text -RightsFilter $txtRightsFilter.Text -ShowInheritedOnly $chkShowInheritedOnly.IsChecked
$dgPermissions.ItemsSource = $filteredData
$txtPermissionCount.Text = "Einträge: $($filteredData.Count) von $($Global:PermissionsData.Count)"
$txtStatus.Text = "Berechtigungen erfolgreich aktualisiert"
}
finally {
$window.Cursor = [System.Windows.Input.Cursors]::Arrow
}
}
})
$btnExit.Add_Click({
$window.Close()
})
# Neue Event Handler
$btnBackup.Add_Click({
if ([string]::IsNullOrEmpty($Global:CurrentFolder)) {
[System.Windows.MessageBox]::Show("Bitte wählen Sie zuerst einen Ordner aus.", "Hinweis", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Information)
return
}
$txtStatus.Text = "Erstelle Backup..."
$window.Cursor = [System.Windows.Input.Cursors]::Wait
try {
$backupFile = Backup-FolderPermissions -FolderPath $Global:CurrentFolder
if ($backupFile) {
$txtStatus.Text = "Backup erfolgreich erstellt: $(Split-Path $backupFile -Leaf)"
}
}
finally {
$window.Cursor = [System.Windows.Input.Cursors]::Arrow
}
})
$btnApplyFilter.Add_Click({
if ($Global:PermissionsData.Count -gt 0) {
$filteredData = Get-FilteredPermissions -Permissions $Global:PermissionsData -UserFilter $txtUserFilter.Text -RightsFilter $txtRightsFilter.Text -ShowInheritedOnly $chkShowInheritedOnly.IsChecked
$dgPermissions.ItemsSource = $filteredData
$txtPermissionCount.Text = "Einträge: $($filteredData.Count) von $($Global:PermissionsData.Count)"
$txtStatus.Text = "Filter angewendet"
}
})
$btnRemovePermission.Add_Click({
if ([string]::IsNullOrEmpty($Global:CurrentFolder)) {
[System.Windows.MessageBox]::Show("Bitte wählen Sie zuerst einen Ordner aus.", "Hinweis", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Information)
return
}
if ([string]::IsNullOrEmpty($txtUsername.Text)) {
[System.Windows.MessageBox]::Show("Bitte geben Sie einen Benutzernamen ein.", "Hinweis", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Information)
return
}
$username = $txtUsername.Text
$applyTo = "MainOnly"
if ($rbSubOnly.IsChecked) { $applyTo = "SubOnly" }
elseif ($rbBoth.IsChecked) { $applyTo = "Both" }
$result = [System.Windows.MessageBox]::Show("Möchten Sie alle Berechtigungen für '$username' wirklich entfernen?", "Bestätigung", [System.Windows.MessageBoxButton]::YesNo, [System.Windows.MessageBoxImage]::Question)
if ($result -eq [System.Windows.MessageBoxResult]::Yes) {
$txtStatus.Text = "Entferne Berechtigung..."
$window.Cursor = [System.Windows.Input.Cursors]::Wait
try {
$success = Remove-FolderPermission -FolderPath $Global:CurrentFolder -Username $username -ApplyTo $applyTo
if ($success) {
$txtStatus.Text = "Berechtigung erfolgreich entfernt für: $username - $applyTo"
$txtUsername.Text = ""
# Berechtigungen neu laden
$includeSubfolders = $chkIncludeSubfolders.IsChecked
$Global:PermissionsData = Get-FolderPermissions -FolderPath $Global:CurrentFolder -IncludeSubfolders $includeSubfolders
$filteredData = Get-FilteredPermissions -Permissions $Global:PermissionsData -UserFilter $txtUserFilter.Text -RightsFilter $txtRightsFilter.Text -ShowInheritedOnly $chkShowInheritedOnly.IsChecked
$dgPermissions.ItemsSource = $filteredData
$txtPermissionCount.Text = "Einträge: $($filteredData.Count) von $($Global:PermissionsData.Count)"
}
}
finally {
$window.Cursor = [System.Windows.Input.Cursors]::Arrow
}
}
})
$btnExportCsv.Add_Click({
if ($Global:PermissionsData.Count -eq 0) {
[System.Windows.MessageBox]::Show("Keine Daten zum Exportieren vorhanden.", "Hinweis", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Information)
return
}
# Erweiterte Export-Optionen
$exportChoice = [System.Windows.MessageBox]::Show("Welches Format möchten Sie verwenden?`n`nJa = CSV-Datei`nNein = HTML-Report`nAbbrechen = Vorgang abbrechen", "Export-Format wählen", [System.Windows.MessageBoxButton]::YesNoCancel, [System.Windows.MessageBoxImage]::Question)
if ($exportChoice -eq [System.Windows.MessageBoxResult]::Cancel) {
return
}
$saveDialog = New-Object System.Windows.Forms.SaveFileDialog
$timestamp = Get-Date -Format 'yyyy-MM-dd_HH-mm-ss'
if ($exportChoice -eq [System.Windows.MessageBoxResult]::Yes) {
# CSV Export
$saveDialog.Filter = "CSV Dateien (*.csv)|*.csv"
$saveDialog.FileName = "FolderPermissions_$timestamp.csv"
$dialogResult = $saveDialog.ShowDialog()
if ($dialogResult -eq [System.Windows.Forms.DialogResult]::OK) {
try {
$Global:PermissionsData | Export-Csv -Path $saveDialog.FileName -NoTypeInformation -Encoding UTF8
$txtStatus.Text = "CSV erfolgreich exportiert: $(Split-Path $saveDialog.FileName -Leaf)"
}
catch {
[System.Windows.MessageBox]::Show("Fehler beim CSV-Export: $($_.Exception.Message)", "Fehler", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Error)
}
}
} else {
# HTML Export
$saveDialog.Filter = "HTML Dateien (*.html)|*.html"
$saveDialog.FileName = "FolderPermissions_Report_$timestamp.html"
$dialogResult = $saveDialog.ShowDialog()
if ($dialogResult -eq [System.Windows.Forms.DialogResult]::OK) {
try {
Export-PermissionsToHtml -Permissions $Global:PermissionsData -FilePath $saveDialog.FileName
$txtStatus.Text = "HTML-Report erfolgreich exportiert: $(Split-Path $saveDialog.FileName -Leaf)"
# Optional: HTML-Datei öffnen
$openResult = [System.Windows.MessageBox]::Show("HTML-Report wurde erstellt. Möchten Sie ihn jetzt öffnen?", "Report erstellt", [System.Windows.MessageBoxButton]::YesNo, [System.Windows.MessageBoxImage]::Question)
if ($openResult -eq [System.Windows.MessageBoxResult]::Yes) {
Start-Process $saveDialog.FileName
}
}
catch {
[System.Windows.MessageBox]::Show("Fehler beim HTML-Export: $($_.Exception.Message)", "Fehler", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Error)
}
}
}
})
$btnBrowseUser.Add_Click({
try {
$txtStatus.Text = "Lade Benutzer und Gruppen..."
$window.Cursor = [System.Windows.Input.Cursors]::Wait
$users = Get-SystemUsers
if ($users.Count -eq 0) {
[System.Windows.MessageBox]::Show("Keine Benutzer oder Gruppen gefunden.", "Information", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Information)
return
}
# Einfacher Auswahldialog
$selectedUser = $users | Out-GridView -Title "Benutzer oder Gruppe auswählen" -OutputMode Single
if ($selectedUser) {
$txtUsername.Text = $selectedUser.Name
$txtStatus.Text = "Benutzer ausgewählt: $($selectedUser.FullName)"
} else {
$txtStatus.Text = "Keine Auswahl getroffen"
}
}
catch {
Write-LogEntry "Fehler beim Laden der Benutzer: $($_.Exception.Message)" "ERROR"
$txtStatus.Text = "Fehler beim Laden der Benutzer"
}
finally {
$window.Cursor = [System.Windows.Input.Cursors]::Arrow
}
})
# DataGrid Selection Event
$dgPermissions.Add_SelectionChanged({
$btnRemoveSelected.IsEnabled = $dgPermissions.SelectedItems.Count -gt 0
})
# Ausgewählte Berechtigungen entfernen
$btnRemoveSelected.Add_Click({
if ($dgPermissions.SelectedItems.Count -eq 0) {
[System.Windows.MessageBox]::Show("Bitte wählen Sie mindestens eine Berechtigung aus.", "Hinweis", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Information)
return
}