Remote process execution using PsExec

27 views Asked by At

When attempting to run the .exe file as a remote process, the log indicates a "Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'" error.

While attempting to achieve the desired results using a C# application with the PsExec tool, I'm encountering issues, and the results obtained differ from those obtained through the command prompt and I've also explored alternatives such as WMI and PowerShell remoting. I've tried the following c# code to achieve the remote execution of .exe file and facing the error as "Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'". How to achieve the desired results of execute remote process successfully?

SecureString password = new SecureString();
        foreach (char c in "YourPassword")
        {
            password.AppendChar(c);
        }

        Process p = new Process
        {
            StartInfo =
                                {
                                    FileName = @"C:\Users\user1\Downloads\PSTools\psexec.exe",
                                    UserName = "user1",
                                    Password = password,
                                    Domain = "domain",
                                    RedirectStandardOutput = true,
                                    RedirectStandardError = true,
                                    UseShellExecute = false,
                                    CreateNoWindow = true,                                        
                                    Arguments = $@"\\RemoteMachineName ""C:\Program Files (x86)\BizTalkBPA\BizTalkBPACmd.exe""",
                                }
        };

        p.Start();
        string output = p.StandardOutput.ReadToEnd();
        Console.WriteLine(output);
        Console.ReadLine();
        string error = p.StandardError.ReadToEnd();
        output = string.Concat(output, Environment.NewLine, error);
        p.WaitForExit();
0

There are 0 answers