问题描述
假设我在网络上的多台计算机上都有一个名为"MyService"的Windows服务和一个名为"MyEXE"的可执行文件.
是否可以(从"MyService"内部)在不同/相同的计算机上启动"MyEXE"的多个实例,是否可以执行某些任务并向"MyService"中的回调方法返回真/假结果?/p>
类似这样的东西
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);
}
}
也许我弄错了整个架构!
您可以像Ian所说的那样使用PSexec,但是我认为WMI是一个更好的尝试方法,例如 http://www.codeproject.com/KB/cs/EverythingInWmi02.aspx
Let's say I have a windows service called "MyService" and an executable called "MyEXE" located on several computers on my network.
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"?
Something like this
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!
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中的另一台计算机上运行进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!