我成功实现了 如何以编程方式调用 Windows 权限对话框?及相关: 如何从 c# 显示文件属性对话框安全选项卡。
public static bool ShowFileProperties(string Filename)
{
SHELLEXECUTEINFO info = new SHELLEXECUTEINFO();
info.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(info);
info.lpVerb = "properties";
info.lpFile = Filename;
info.lpParameters = "Security";
info.nShow = SW_SHOW;
info.fMask = SEE_MASK_INVOKEIDLIST;
return ShellExecuteEx(ref info);
}
Run Code Online (Sandbox Code Playgroud)
但是,我想像使用该对话框中的“编辑..”按钮一样进入“权限”窗口。
有任何想法吗?
小智 2
您可以通过编程方式单击“编辑...”按钮:
从这里编辑的示例,与屏幕截图中看到的窗口标题匹配:
private void clickEdit()
{
// Look for a top-level window/application called "SupportAssist Properties"
var root = AutomationElement.RootElement;
var condition1 = new PropertyCondition(AutomationElement.NameProperty, "SupportAssist Properties");
var treeWalker = new TreeWalker(condition1);
AutomationElement element = treeWalker.GetFirstChild(root);
if (element == null)
{
// not found
return;
}
// great! window found
var window = element;
// now look for a button with the text "Edit..."
var buttonElement = window.FindFirst(TreeScope.Descendants,
new PropertyCondition(AutomationElement.NameProperty, "Edit.."));
if (buttonElement == null)
{
// not found
return;
}
// great! now click the button
var invokePattern = buttonElement.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern;
invokePattern?.Invoke();
}
Run Code Online (Sandbox Code Playgroud)
重要的!该代码的链接源内容如下:
var buttonElement = window.FindFirst(TreeScope.Children
Run Code Online (Sandbox Code Playgroud)
但这在“属性”窗口中不起作用。在此级别中找不到“编辑...”。你必须更深一层地搜索它:
var buttonElement = window.FindFirst(TreeScope.Descendants
Run Code Online (Sandbox Code Playgroud)