3

I want to create a simple application to launch another application under different credentials.

Both application are on my laptop which is not on the domain. I need to run SSMS using a domain user credentials.

When I use the following runas command, it works:

runas.exe /netonly /user:domain\username /password:mypass "C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\Ssms.exe"

The following code IS NOT working :

        var file = @"C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\Ssms.exe";
        var sspw = new SecureString();
        foreach (var c in "mypass" sspw.AppendChar(c);

        var proc = new Process();
        proc.StartInfo.UseShellExecute = false;
        proc.StartInfo.WorkingDirectory = Path.GetDirectoryName(file);
        proc.StartInfo.FileName = Path.GetFileName(file);
        proc.StartInfo.Arguments = "";
        proc.StartInfo.Domain = "domain";
        proc.StartInfo.UserName = "username";
        proc.StartInfo.Password = sspw;
        proc.StartInfo.LoadUserProfile = true;

        proc.Start();

The exception message is:

Logon failure: unknown user name or bad password
Baral
  • 3,103
  • 2
  • 19
  • 28
  • Possible duplicate of http://stackoverflow.com/questions/757857/how-to-build-runas-netonly-functionality-into-a-c-net-winforms-program – Sven Grosen Feb 27 '14 at 16:46

0 Answers0