Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically open Advanced Security Settings dialog?

Is there a way to open the Advanced Security Settings dialog for a directory/file programmatically? This is the dialog I want to open:

Advanced Security Dialog

You open it by clicking the Advanced button on the Security properties dialog for the directory/file.

Security Properties

There is this answer that shows how to open the Security properties tab using ShellExecuteEx, so perhaps there are different parameters that can be used to open the Advanced Security Settings dialog directly, but I don't know where to find documentation (or where to look in the registry) for the verbs/parameters supported.

There is also the EditSecurityAdvanced API, but it looks like that requires implementing the functionality to get/set the ACL instead of using the functionality built in to the Windows shell.

I'm working in VB.NET, but can translate C# or Windows API calls as needed, and pointers for how to do my own research would also be appreciated.

like image 533
Mark Avatar asked Dec 01 '16 16:12

Mark


1 Answers

I couldn't find a direct way of opening it either. Using automation like the commentator Visual Vincent suggested isn't too hard. Don't forget to add references to the assemblies and import System.Windows.Automation

Then this code should press the Advanced button for you. This way still creates the main properties dialog though.

Dim FileName As String = "The file name you are viewing the properties of"
Dim AE As AutomationElement = AutomationElement.RootElement.FindFirst(TreeScope.Children, New PropertyCondition(AutomationElement.NameProperty, FileName + " Properties"))
Dim Advancedbtn = AE.FindFirst(TreeScope.Element Or TreeScope.Descendants, New PropertyCondition(AutomationElement.NameProperty, "Advanced"))
TryCast(Advancedbtn.GetCurrentPattern(InvokePattern.Pattern), InvokePattern).Invoke()
like image 137
Evan P Avatar answered Nov 15 '22 08:11

Evan P