Let's say I have a windows service called "MyService" and an executable called "MyEXE" located on several computers on my network.
假设我有一个名为“MyService”的Windows服务和一个名为“MyEXE”的可执行文件,位于我网络上的几台计算机上。
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"?
是否可以(在“MyService”中)在不同/相同的计算机上启动“MyEXE”的多个实例,让它执行某项任务并将“true / false”结果返回到“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!
也许我的整个架构都错了!
4 个解决方案
#1
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
你可以像Ian所说的那样使用PSexec,但我认为WMI是一个更好的方法,试试这个例子http://www.codeproject.com/KB/cs/EverythingInWmi02.aspx
#2
One thing you can do is run the PsExec tool (http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx) from Sysinternals in a separate process, pipe the result to a file, then parse it to figure out success/failure.
您可以做的一件事是在一个单独的进程中从Sysinternals运行PsExec工具(http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx),将结果传递给一个文件,然后将其解析为数字成功/失败。
#3
One solution is to use psexec, the other is to... do what psexec does:
一种解决方案是使用psexec,另一种解决方案是......执行psexec所做的事情:
- embed a service exe as a resource into your app
- copy the resource into \\remotesystem\admin$
- use SCM to start a this exe as a service on \\remotesystem
- connect ask the service to do the work
- uninstall the service from SCM
将服务exe作为资源嵌入到您的应用中
将资源复制到\\ remotesystem \ admin $
使用SCM在\\ remotesystem上启动此exe作为服务
连接要求服务完成工作
从SCM卸载服务
#4
Also see Task Manager API. You schedule a task to run once now+1 sec, etc. It's COM-based, so quite .NET-friendly.
另请参阅任务管理器API。你安排一个任务现在运行一次+ 1秒,等等。它是基于COM的,所以非常适合.NET。
Unlike psexec, this does not install anything on the target machine.
与psexec不同,它不会在目标机器上安装任何东西。
#1
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
你可以像Ian所说的那样使用PSexec,但我认为WMI是一个更好的方法,试试这个例子http://www.codeproject.com/KB/cs/EverythingInWmi02.aspx
#2
One thing you can do is run the PsExec tool (http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx) from Sysinternals in a separate process, pipe the result to a file, then parse it to figure out success/failure.
您可以做的一件事是在一个单独的进程中从Sysinternals运行PsExec工具(http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx),将结果传递给一个文件,然后将其解析为数字成功/失败。
#3
One solution is to use psexec, the other is to... do what psexec does:
一种解决方案是使用psexec,另一种解决方案是......执行psexec所做的事情:
- embed a service exe as a resource into your app
- copy the resource into \\remotesystem\admin$
- use SCM to start a this exe as a service on \\remotesystem
- connect ask the service to do the work
- uninstall the service from SCM
将服务exe作为资源嵌入到您的应用中
将资源复制到\\ remotesystem \ admin $
使用SCM在\\ remotesystem上启动此exe作为服务
连接要求服务完成工作
从SCM卸载服务
#4
Also see Task Manager API. You schedule a task to run once now+1 sec, etc. It's COM-based, so quite .NET-friendly.
另请参阅任务管理器API。你安排一个任务现在运行一次+ 1秒,等等。它是基于COM的,所以非常适合.NET。
Unlike psexec, this does not install anything on the target machine.
与psexec不同,它不会在目标机器上安装任何东西。