使用其他用户权限运行Explorer / Folderbrowserdialog

时间:2017-10-10 14:04:09

标签: c# windows impersonation

我有一个应该能够在另一个用户上下文中运行显式任务的应用程序,因此在应用程序中,权限较低的用户可以执行某些任务,但是不允许他这样做。

我使用了这个模拟,它与正常的代码一起正常工作,但我无法使用Folderbrowser对话框。我认为浏览器是在正确的用户的上下文中执行的,但是使用了覆盖用户上下文的其他窗口函数。

我的代码不起作用是:

    private void tb_customRoot_MouseDoubleClick(object sender, MouseButtonEventArgs e)
    {
        ImpersonationHelper.Impersonate("STARK", VSSFileExplorer.Properties.Settings.Default.FS_User, BASE64.Base64Decode(VSSFileExplorer.Properties.Settings.Default.FS_Password), delegate
            {
                VistaFolderBrowserDialog myFancyFolderDialog = new VistaFolderBrowserDialog();
                DirectoryInfo rootDir = new DirectoryInfo(@"C:\");

                try
                {
                    rootDir = new DirectoryInfo(VSSFileExplorer.Properties.Settings.Default.CustomRoot);
                }
                catch
                { throw; }

                myFancyFolderDialog.SelectedPath = rootDir.ToString();
                myFancyFolderDialog.ShowDialog();

                tb_customRoot.Text = myFancyFolderDialog.SelectedPath;
            });
    }

问题是,在打开浏览器对话框后,Windows会打开一个"输入网络凭据"登录提示。用户不应该知道此凭据。 有没有办法用另一个用户权限运行Folderbrowserdialog?

我还构建了一个函数,它将从GUI中的某些工具生成正确的路径,但如果可能的话,我真的很感兴趣。

提前致谢。

0 个答案:

没有答案