From c369ee18e72b3624ab50798615940177c1da61a4 Mon Sep 17 00:00:00 2001 From: duffyduck Date: Mon, 22 Dec 2025 10:14:20 +0100 Subject: [PATCH] =?UTF-8?q?dialogcheckbox=20hinzugef=C3=BCgt=20um=20ganzen?= =?UTF-8?q?=20pfad=20reinzupacken?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Freigabe-Hinzufuegen.ps1 | 70 ++++++++++++++++++++++++++++++---------- 1 file changed, 53 insertions(+), 17 deletions(-) diff --git a/Freigabe-Hinzufuegen.ps1 b/Freigabe-Hinzufuegen.ps1 index 5947243..1717909 100644 --- a/Freigabe-Hinzufuegen.ps1 +++ b/Freigabe-Hinzufuegen.ps1 @@ -128,7 +128,7 @@ function Show-UserSelectionDialog { $form = New-Object System.Windows.Forms.Form $form.Text = "Benutzer ausw$([char]0x00E4)hlen - Freigabe" - $form.Size = New-Object System.Drawing.Size(450, 500) + $form.Size = New-Object System.Drawing.Size(450, 530) $form.StartPosition = "CenterScreen" $form.FormBorderStyle = "FixedDialog" $form.MaximizeBox = $false @@ -146,7 +146,7 @@ function Show-UserSelectionDialog { $listBox = New-Object System.Windows.Forms.ListBox $listBox.Location = New-Object System.Drawing.Point(10, 45) - $listBox.Size = New-Object System.Drawing.Size(410, 360) + $listBox.Size = New-Object System.Drawing.Size(410, 330) $listBox.Font = New-Object System.Drawing.Font("Segoe UI", 10) $form.Controls.Add($listBox) @@ -166,9 +166,24 @@ function Show-UserSelectionDialog { } }) + $chkFullPath = New-Object System.Windows.Forms.CheckBox + $chkFullPath.Text = "Kompletten Pfad in Verkn$([char]0x00FC)pfungsname schreiben" + $chkFullPath.Location = New-Object System.Drawing.Point(10, 385) + $chkFullPath.Size = New-Object System.Drawing.Size(410, 25) + $chkFullPath.Font = New-Object System.Drawing.Font("Segoe UI", 9) + $form.Controls.Add($chkFullPath) + + $lblExample = New-Object System.Windows.Forms.Label + $lblExample.Text = "(z.B. 'Mandanten - S - Schmidt - Lohn' statt nur 'Lohn')" + $lblExample.Location = New-Object System.Drawing.Point(27, 408) + $lblExample.Size = New-Object System.Drawing.Size(400, 20) + $lblExample.ForeColor = [System.Drawing.Color]::Gray + $lblExample.Font = New-Object System.Drawing.Font("Segoe UI", 8) + $form.Controls.Add($lblExample) + $okBtn = New-Object System.Windows.Forms.Button $okBtn.Text = "Freigeben" - $okBtn.Location = New-Object System.Drawing.Point(240, 420) + $okBtn.Location = New-Object System.Drawing.Point(240, 450) $okBtn.Size = New-Object System.Drawing.Size(85, 30) $okBtn.Enabled = $false $okBtn.DialogResult = [System.Windows.Forms.DialogResult]::OK @@ -177,7 +192,7 @@ function Show-UserSelectionDialog { $cancelBtn = New-Object System.Windows.Forms.Button $cancelBtn.Text = "Abbrechen" - $cancelBtn.Location = New-Object System.Drawing.Point(335, 420) + $cancelBtn.Location = New-Object System.Drawing.Point(335, 450) $cancelBtn.Size = New-Object System.Drawing.Size(85, 30) $cancelBtn.DialogResult = [System.Windows.Forms.DialogResult]::Cancel $form.CancelButton = $cancelBtn @@ -195,13 +210,18 @@ function Show-UserSelectionDialog { }) $script:selectedUser = $null + $script:useFullPath = $false if ($form.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK -and $listBox.SelectedIndex -ge 0) { $selectedText = $listBox.SelectedItem $script:selectedUser = $script:allUsers | Where-Object { $_.FullName -eq $selectedText } | Select-Object -First 1 + $script:useFullPath = $chkFullPath.Checked } - return $script:selectedUser + return @{ + User = $script:selectedUser + UseFullPath = $script:useFullPath + } } function Add-FreigabePermission { @@ -290,34 +310,50 @@ try { throw "Keine Benutzer gefunden!" } - $selectedUser = Show-UserSelectionDialog -Users $users - if (-not $selectedUser) { + $dialogResult = Show-UserSelectionDialog -Users $users + if (-not $dialogResult.User) { exit 0 } - + + $selectedUser = $dialogResult.User + $useFullPath = $dialogResult.UseFullPath + $userName = $selectedUser.SamAccountName $userFolder = Join-Path $basePath $userName - + if (-not (Test-Path $userFolder)) { New-Item -Path $userFolder -ItemType Directory -Force | Out-Null } - + $uncPath = Get-UNCPath -LocalPath $Path - $itemName = Split-Path -Path $Path -Leaf + + # Verknuepfungsname erstellen + if ($useFullPath) { + # Kompletten Pfad verwenden: \\server\Mandanten\S\Schmidt\Lohn -> Mandanten - S - Schmidt - Lohn + $pathForName = $uncPath + # UNC-Prefix und Servernamen entfernen + if ($pathForName -match '^\\\\[^\\]+\\(.+)$') { + $pathForName = $Matches[1] + } + # Backslashes durch " - " ersetzen + $itemName = $pathForName -replace '\\', ' - ' + } else { + $itemName = Split-Path -Path $Path -Leaf + } + $shortcutPath = Join-Path $userFolder "$itemName.lnk" - + $counter = 1 while (Test-Path $shortcutPath) { - $baseName = [System.IO.Path]::GetFileNameWithoutExtension($itemName) - $extension = [System.IO.Path]::GetExtension($itemName) - $shortcutPath = Join-Path $userFolder "$baseName ($counter)$extension.lnk" + $baseName = $itemName + $shortcutPath = Join-Path $userFolder "$baseName ($counter).lnk" $counter++ } - + Create-Shortcut -TargetPath $uncPath -ShortcutPath $shortcutPath Add-FreigabePermission -TargetPath $Path -QualifiedUserName $selectedUser.QualifiedName Save-FreigabeInfo -TargetPath $Path -UserName $selectedUser.QualifiedName - + [System.Windows.Forms.MessageBox]::Show( "Freigabe erfolgreich erstellt!`n`nBenutzer: $($selectedUser.DisplayName)`nVerkn$([char]0x00FC)pfung: $shortcutPath`nUNC-Pfad: $uncPath", "Freigabe erfolgreich",