以另一个域用户身份运行应用程序

时间:2018-07-27 12:57:35

标签: c# authentication windows-10 impersonation

我有一个可以自动启动其他程序的程序。

其中一个程序是Active Directory管理中心DSAC.EXE。

要以正确的权限正确使用它,必须从另一个用户启动它。域管理员用户。他们白天配置文件的确切副本,但具有增强的特权。

我有这段代码可与Windows 7完美配合,但不适用于Windows 10:

if (Properties.Settings.Default.AS_P_CAD == true)
            {
                if (File.Exists(@"C:\Windows\system32\dsac.exe") | File.Exists(@"C:\Windows\sysnative\dsac.exe"))
                {
                    Process[] CAD_Process = Process.GetProcessesByName("dsac.exe");
                    if (CAD_Process.Length == 0)
                    {
                        try
                        {
                            Process proc = new Process();
                            System.Security.SecureString ssPwd = new System.Security.SecureString();
                            proc.StartInfo.UseShellExecute = false;
                            proc.StartInfo.FileName = "dsac.exe";
                            //proc.StartInfo.Arguments = "args...";
                            proc.StartInfo.Domain = "somedomain.local";
                            proc.StartInfo.UserName = Crypto.Decrypt(Properties.Settings.Default.ADM_Login);
                            string password = Crypto.Decrypt(Properties.Settings.Default.ADM_);
                            for (int x = 0; x < password.Length; x++)
                            {
                                ssPwd.AppendChar(password[x]);
                            }
                            password = "";
                            proc.StartInfo.Password = ssPwd;
                            proc.Start();
                        }
                        catch (Exception ex)
                        {
                            dMessageBox.Show("Information", $"Active Directory Administrative Center could not be launched.\n\nError :\n{ex.Message}", MessageBoxIcon.Information);
                        }
                    }
                    else
                    {
                        dMessageBox.Show("Already running", "Active Directory Administrative Center is already running", MessageBoxIcon.Information);
                    }
                }
                else
                {
                    dMessageBox.Show("Canceled", "Active Directory Administrative Center is not installed.\nThere is nothing to launch !", MessageBoxIcon.Information);
                }
            }

我尝试了其他多种解决方案,其中一种是与Impersonator一起使用的,但似乎没有任何效果。

消息“被用户取消”。

我遇到了一个使用CreateProcessWithLogonW的解决方案,但是我不知道如何使用它。

有什么想法吗?


编辑:

我已经尝试过模仿(Impersonate):失败

使用CreateProcessWithLogonW:失败(仍然返回“需要海拔”)

可以通过禁用UAC来完成吗?并立即重新启用它?

还是通过批处理或控制台线?

请帮助。


EDIT#2:

处理通过CreateProcessWithLogonW启动的.bat文件。

这太荒谬了。我讨厌Win10。 :x

0 个答案:

没有答案