如何在 .net 中的另一台计算机上运行进程 [英] How can you run a process on another computer in .net

查看:33
本文介绍了如何在 .net 中的另一台计算机上运行进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个名为MyService"的 Windows 服务和一个名为MyEXE"的可执行文件,位于我网络上的多台计算机上.

Let's say I have a windows service called "MyService" and an executable called "MyEXE" located on several computers on my network.

是否可以(从MyService"中)在不同/同一台计算机上启动多个MyEXE"实例,让它执行一些任务并将真/假结果返回给MyService"中的回调方法?

Is it possible (from within "MyService") to start several instances of "MyEXE" on a different/same computer, have it do some task and return a true/false result to a callback method in "MyService"?

类似的东西

class MyService : ServiceBase
{
    delegate void UpdateCallBack(int id, bool updated)
    void CheckForUpdates()
    {
        bool updatesExist = someService.GetCurrentVersion() != currentVersion;
        if(updatesExist)
        {
            UpdatePC("C:\Program Files\MyApp.exe", 1, UpdateComplete);
            UpdatePC("\\somepc\Program Files\MyApp.exe", 1, UpdateComplete);
            UpdatePC("\\mypc\Program Files\MyApp.exe", 1, UpdateComplete);
        }
    }

    void UpdatePC(string filePath, int id, UpdateCallBack callback)
    {
       //This is where I am kind of lost 
       SomeEXERunner runner = new SomeEXERunner();
       runner.Run(filePath,"-u",id,callback);
    }

    void UpdateComplete(int id, bool updated)
    {
       //do something
       if(!updated)
          EmailService.NotifyAdmin("PC Not updated", id);
    }
}

也许我弄错了整个架构!

Maybe I'm getting the whole architecture wrong!

推荐答案

你可以像 Ian 所说的那样使用 PSexec,但我认为 WMI 是一个更好的方法试试这个例子 http://www.codeproject.com/KB/cs/EverythingInWmi02.aspx

You could use PSexec as Ian stated, but I think WMI is a better way try this for an example http://www.codeproject.com/KB/cs/EverythingInWmi02.aspx

这篇关于如何在 .net 中的另一台计算机上运行进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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