1

I have an exe which I can run in console like below

util.exe argument1

I need to invoke this from a CSharp application which I can do like below

  private string Command(string arg)
  {
            var p = new Process
            {
                StartInfo =
                {
                    FileName = "util.exe",
                    Arguments = arg,
                    RedirectStandardOutput = true,
                    RedirectStandardInput = true,
                    CreateNoWindow = true,
                    UseShellExecute = false
                }
            };

            var stdOutput = new StringBuilder();
            p.OutputDataReceived += (sender, args) => stdOutput.AppendLine(args.Data);

            p.Start();
            p.BeginOutputReadLine();
            p.WaitForExit();

            return stdOutput.ToString();
 }


 var result = Command(argument1) //call

However there is an issue. util.exe authenticates user using the Windows logged in credentials. In the application I need to execute the commands as a different user(Like below)

 util.exe login funcationaluser fuucntioanluserpwd
 util.exe argument1

What is the right way for doing this? Can I reuse the process?

Edit: Please note the username and password is specific to util.exe , not a system username/password

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Jimmy
  • 3,224
  • 5
  • 29
  • 47
  • Possible duplicate of [Run .bat file through C# code as different user silently](https://stackoverflow.com/questions/4650738/run-bat-file-through-c-sharp-code-as-different-user-silently) – rene Sep 29 '17 at 13:36
  • Another duplicate would be this [Start a .Net Process as a different user](https://stackoverflow.com/questions/4624113/start-a-net-process-as-a-different-user) – Hack Sep 29 '17 at 13:38
  • It is not logging in as a different windows user. The user name and password is specific to the exe to be executed(util.exe) – Jimmy Sep 29 '17 at 13:40
  • ah, so it takes in credentials as arguments? So are you asking how to write a method that will do both the login command and the argument1 command? – Hack Sep 29 '17 at 13:43
  • @Hack yes that is the intention – Jimmy Sep 29 '17 at 13:44
  • Perhaps I need to invoke cmd.exe? – Jimmy Sep 29 '17 at 13:46
  • After getting a few more details the answer I posted won't work for you so I deleted it. I've done what your asking before, but its been years so i'd have to do a little bit of a refresher to remember how i did it before. If this hasn't been answered later today I may post a better answer later. – Hack Sep 29 '17 at 14:35

0 Answers0