在 wmi 中的远程计算机上启动程序,同时打开应用程序窗口(在 C# 中)
我在网络上浏览了一页又一页的数据,似乎每个人都说您无法让可执行文件通过 WMI 在另一台计算机上远程执行应用程序并显示该应用程序的窗口。
有谁知道解决这个问题的方法吗?
我尝试创建 2 个可执行文件。 1 个可执行文件使用 Process 类并简单地启动一个可执行文件。 代码如下:
class Program
{
static void Main( string[ ] args )
{
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.CreateNoWindow = false;
startInfo.UseShellExecute = false;
startInfo.FileName = "C:\\folder\\Mexe.exe";
startInfo.WindowStyle = ProcessWindowStyle.Normal;
//p.MachineName="server";
//p.Start(startInfo);
Process p = Process.Start( startInfo );
}
}
该可执行文件驻留在远程计算机上。
我有另一个可执行文件将位于客户端的计算机上。 该exe使用C#中的WMI通过命令行远程执行服务器上的应用程序。 我得到的返回码为 0。服务器上没有任何反应。
有什么想法我可能做错了什么吗?
我还考虑过在服务器上的任务计划程序中创建计划任务,但禁用该任务。
任何人都知道让 WMI 应用程序启动此任务的 C# 代码是什么? 有没有办法判断任务/应用程序是否启动完成?
I've browsed page after page after page of data on the web and everyone seems to say that you cannot have an executable remotely execute an application on another machine via WMI and have the window of that application display.
Does anyone know a way around this?
I have tried created 2 executables. 1 executable uses the Process class and simply starts an executable. Here's the code:
class Program
{
static void Main( string[ ] args )
{
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.CreateNoWindow = false;
startInfo.UseShellExecute = false;
startInfo.FileName = "C:\\folder\\Mexe.exe";
startInfo.WindowStyle = ProcessWindowStyle.Normal;
//p.MachineName="server";
//p.Start(startInfo);
Process p = Process.Start( startInfo );
}
}
This executable resides on the remote machine.
I have another executable that will be on the client's machine. This exe uses WMI in C# to remotely execute the application on the server via the commandline. I get a return code of 0. Nothing happens on the server.
Any ideas what I might be doing wrong?
I've also thought about creating a scheduled task in task scheduler on the server, but leaving the task disabled.
Anyone have an idea what the C# code would be to have a WMI application kick off this task? Would there be a way to discern whether the task/application started finished?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我相信您必须使用 Win32_ScheduledJob.Create 远程创建交互式进程。
请参阅
http://msdn.microsoft.com/en -us/library/aa389769%28VS.85%29.aspx
您可以将其安排为现在 +1 秒。
You have to use Win32_ScheduledJob.Create to create an interactive process remotely I believe.
See
http://msdn.microsoft.com/en-us/library/aa389769%28VS.85%29.aspx
You can just schedule it for Now +1 second.
如果您的命令行字符串正常,进程名称 (Mexe.exe) 应该出现在 Windows 任务管理器的进程列表中,即使它是不可见的。 我也看到过资料说可以使用计划任务让进程可见,但没尝试过。 一旦确认进程已创建,您可以尝试为其创建计划任务并使用 Win32_Process.Start() 运行它。
If your command line string is OK, the process name (Mexe.exe) should appear in the process list in Windows Task Manager even if it is invisible. I have also seen information that you can use scheduled tasks to make the process visible, but never tried it. Once you confirm that the process gets created you could try creating a scheduled task for it and running it using Win32_Process.Start().
您可能已将“Mexe.exe”制作为控制台应用程序。 在您的代码中,startInfo 描述了一个 Windows 应用程序。 尝试将“Mexe.exe”制作为 Windows 应用程序。 我已经为控制台和 Windows 应用程序尝试了您的代码,并且它适用于 Windows 应用程序。
您还可以直接使用客户端上的一个可执行文件来完成此操作。无需中间服务器可执行文件来调用“Mexe.exe”。 只是提高性能的建议..
you might have made 'Mexe.exe' as a console application. In your code , startInfo describes a windows application. try making the 'Mexe.exe' as a windows application. i have tried your code for both console and windows application and it worked for windows application.
And also you can do this directly with just one executable on client.No need of an intermediate server executable to invoke 'Mexe.exe'. Is just a suggestion to improve perfomance..