如何执行远程服务器上的一个bat文件? [英] How to execute a bat file on remote server?

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

问题描述

我有两个物理机。第一台机器要执行的第二台机器上的一个bat文件。我第二个服务器上创建共享位置,并试图从第一台机器上运行它,它不工作。 BAT文件可以在本地机器上正常运行。

I have two physical machine. The first machine want to execute a bat file on the second machine. I create a share location on the second server and tried to run it from the first machine and it does not work. The bat file can run on the local machine properly.

这是bat文件内code的一个例子。这仅仅是一个蝙蝠创建文件。

This is an example of code inside the bat file. It is just a bat to create file.

echo. 2>EmptyFile.txt

这是我用来执行bat文件的code。

This is the code that I use to execute bat file.

private static void ExecuteBatFile()
{
    System.Diagnostics.Process proc = new System.Diagnostics.Process();
    System.Security.SecureString ssPassword = new System.Security.SecureString();

    proc.StartInfo.UseShellExecute = false;
    proc.StartInfo.FileName = @"\\my_remote_server\my_bat.bat";
    proc.StartInfo.Domain = "my_domain";
    proc.StartInfo.UserName = "my_username";

    Console.Write("Enter your password: ");
    string password = Console.ReadLine();

    for (int x = 0; x < password.Length; x++)
    {
        ssPassword.AppendChar(password[x]);
    }

    proc.StartInfo.Password = ssPassword;
    proc.Start();
}

我想知道我怎么可以运行远程服务器上的bat文件?

I want to know how can I run bat file on remote server?

推荐答案

您可以执行使用的 PSEXEC 。我用它来执行批处理文件和参数传递给他们。

You can execute commands on remote machines using PsExec. I use it to execute batch files and pass parameters to them.

这篇关于如何执行远程服务器上的一个bat文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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