简体   繁体   中英

How to execute batch file on multiple remote computers using C#

Is it possible to batch file on remote computers simultaneously? So far I have no luck...

Computer list: Reading from text file. Username: Changes everyday Password: Changes everyday

You can use PsExec to execute commands on a remote machine. So you just have to create and loop through a list containg your computers, usernames and passwords.

For example:

public class RemotePc {
    public RemotePc(string _ServerName, string _UserName, string _Password) {
        ServerName = _ServerName;
        UserName = _UserName;
        Password = _Password;
    }

    public string ServerName { get; set; }

    public string UserName { get; set; }

    public string Password { get; set; }
}

And in your main code of your application add something like this:

List<RemotePc> Pcs = new List<RemotePc>();
Pcs.Add(new RemotePc("Server01", "Administrator", "123456");
Pcs.Add(new RemotePc("Server02", "Administrator", "123456");
//...

foreach (RemotePc Pc in Pcs) {
    //PsExec code
}

You will have to develop and install services on each computer which work as an agent and receive your batch file and commands to execute them.

If you are ready to purchase any software, packages like Octopus Deploy can do that for you : https://octopusdeploy.com/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM