1

是否可以禁用打开文件对话框窗口的某些部分,例如创建新文件夹按钮?

我正在使用的代码示例(取自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"

谢谢

4

1 回答 1

0

好的,根据评论,脚本的这个修改版本会在对话框处于活动状态时禁用在目标目录中创建文件夹的访问权限,然后在函数完成之前删除最后的块:

    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"
于 2013-07-19T01:58:53.030 回答