简体   繁体   English

Powershell-禁用“打开文件”对话框的部分

[英]Powershell - disable parts of Open File Dialog Box

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: 我正在使用的代码示例(摘自http://blogs.technet.com/b/heyscriptingguy/archive/2009/09/01/hey-scripting-guy-september-1.aspx )是:

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"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM