在远程服务器中执行命令 [英] Execute Command in Remote Server

查看:78
本文介绍了在远程服务器中执行命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我的远程服务器名称:MyServerName

操作系统:带SP1的Windows Server 2008 R2

DomainName:MyDomainName

用户名:MyUserName

密码:MyPassWord

My Remote Server Name: MyServerName
Operating System: Windows Server 2008 R2 with SP1
DomainName: MyDomainName
UserName: MyUserName
Password: MyPassWord

我从本地桌面使用远程桌面连接实用程序并且能够使用管理员登录连接到远程服务器(假设MyUserName& 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).

在我的远程桌面中,我必须打开cmd提示符并执行以下命令:

In my remote desktop I have to open cmd prompt and execute the below command:

C:\ Users \ MyyserName \ hpacu

其中" 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.

我正在使用Windows Forms C#准备自动化。

I'm preparing an automation for this using Windows Forms C#.

我的申请表:

1。 TextBox - 从用户(我自己)获取服务器名称。我将给出正确的服务器名称。

1. TextBox - To take server name from the user(myself). I will give the correct server name.

2。按钮 - 使用我的管理员凭据连接到服务器并远程执行硬编码命令。

2. Button - To connect to the server using my administrator credentials and execute the hardcoded command remotely.

3。 PsExec - 此工具位于我的本地计算机中的D-Drive中。该文件的确切位置是  D:\ PSTools \PsExe.exe 

3. PsExec - This tool is placed in D-Drive in my local computer. Exact location of the file is D:\PSTools\PsExe.exe 

注意:我没有收集用于访问远程计算机的用户名和密码,因为我会右键单击windows表单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.

我的C#按钮点击代码:

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.

Mourya

推荐答案

任何人请帮忙。


这篇关于在远程服务器中执行命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆