My Remote Server Name: MyServerName Operating System: Windows Server 2008 R2 with SP1 DomainName: MyDomainName UserName: MyUserName Password: MyPassWord
Iam using Remote Desktop Connection Utility from my local desktop and able to connect to the remote server using administrator login (assuming MyUserName & MyPassWord as administrator login).
In my remote desktop I have to open cmd prompt and execute the below command:
C:\Users\MyUserName\hpacu
Where "hpacu" is a utility which will execute there itself in the command prompt and gives me an output in the same command prompt itself.
I'm preparing an automation for this using Windows Forms C#.
My Application has:
TextBox - To take server name from the user(myself). I will give the correct server name.
Button - To connect to the server using my administrator credentials and execute the hardcoded command remotely.
PsExec - This tool is placed in D-Drive in my local computer. Exact location of the file is D:\PSTools\PsExe.exe
Note: I'm not collecting username and password for accessing remote machine as I would right click on the windows forms exe and execute it as different user - > Give the Administrator credentials along with the domain name of the server, so It wont ask me for username and password to access the server machine.
My C# button click code:
string arg = "cd /d d:/PStools & psexec.exe \\" + txtServerName.Text + " C:\Users\" + MyUserName + "\hpacu & Pause";
System.Diagnostics.Process.Start("CMD.Exe", "/c " + arg);
When I'm clicking on the button, i'm able to connect to the remote machine. I'm also able to launch the command prompt and execute the command. But finally I'm getting the below error: "No process is on the other end of the pipe."
Where as when i try to execute the command manually in the traditional way(that is by connecting via Remote Desktop Utility), the command works perfectly and gives me the output. Please guide me on how to proceed.