Is it possible to disable parts of the open file dialog window such as the create new folder button?
An example of the code I am using (taken from http://blogs.technet.com/b/heyscriptingguy/archive/2009/09/01/hey-scripting-guy-september-1.aspx ) is:
Function Get-FileName($initialDirectory)
{
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") |
Out-Null
$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$OpenFileDialog.initialDirectory = $initialDirectory
$OpenFileDialog.filter = "All files (*.*)| *.*"
$OpenFileDialog.ShowDialog() | Out-Null
$OpenFileDialog.filename
} #end function Get-FileName
Get-FileName -initialDirectory "c:\fso"
Thanks
OK, per the comments, this modified version of your script disables access to create folders within the target directory whilst the dialog is active then removes the block at the end before the function completes:
Function Get-FileName($initialDirectory)
{
<#DENY CreateDirectories privilege
to currently logged on security principal#>
$acl = get-acl $initialDirectory
$right = "CreateDirectories"
$principal = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name
$denyrule = New-Object System.Security.AccessControl.FileSystemAccessRule($principal,$right,"DENY")
$acl.AddAccessRule($denyrule)
set-acl $initialDirectory $acl
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") |
Out-Null
$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$OpenFileDialog.initialDirectory = $initialDirectory
$OpenFileDialog.filter = "All files (*.*)| *.*"
$OpenFileDialog.ReadOnlyChecked = $true
$OpenFileDialog.ShowDialog() | Out-Null
$OpenFileDialog.filename
#remove block now
$acl.RemoveAccessRule($denyrule)
set-acl $initialDirectory $acl
} #end function Get-FileName
Get-FileName -initialDirectory "c:\fso"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.