我们有一个场景,我们需要我们的用户能够使用与当前登录时不同的域启动SQLServer并对其进行身份验证.所以要澄清这个设置的方式:
我们发现从命令行运行它将起作用:
RUNAS /user:REMOTEDOMAIN\AUserName /netonly "C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\Ssms.exe
Run Code Online (Sandbox Code Playgroud)
它将提示"输入REMOTEDOMAIN\AUserName:的密码:",如果您提供了正确的密码,SSMS将启动并可以连接到远程dbs.但是,当我尝试在C#中使用更好的界面做同样的事情时,我得到"登录失败:未知用户名或密码错误",这是我的代码:
System.Security.SecureString password = new System.Security.SecureString();
foreach(char c in txtPassword.Text.ToCharArray()){
password.AppendChar(c);
}
System.Diagnostics.ProcessStartInfo procInfo = new System.Diagnostics.ProcessStartInfo();
procInfo.Arguments = "/netonly";
procInfo.FileName = @"C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\Ssms.exe"; ;
procInfo.Domain = "REMOTEDOMAIN";
procInfo.Verb = "runas";
procInfo.UserName = txtUsername.Text;
procInfo.Password = password;
procInfo.UseShellExecute = false;
System.Diagnostics.Process.Start(procInfo);
Run Code Online (Sandbox Code Playgroud)
我尝试使用带有和没有域预先填写的用户名,但都不起作用.有人试图做类似的事吗?谢谢
您应该删除以下行:
// Not passing /netonly to SMSS, it was passed to RunAs originally.
procInfo.Arguments = "/netonly";
// Again, SMSS is not getting the verb, it's being run
procInfo.Verb = "runas";
Run Code Online (Sandbox Code Playgroud)
基本上,您将/netonly
参数传递给 SMSS ,而在命令行上,您运行的runas
不是 SMSS。与动词相同,你没有跑步runas
。
Start
此时,调用应该会成功,因为您将使用正确的凭据指向正确的可执行文件。