我正在使用 .NET,并疯狂地尝试找到任何有用的 API,让我可以通过 LAN 网络传输文件(当然是通过管理员凭据),然后在该计算机上执行它。
我读过一些使用 WMI 的内容,但谷歌搜索“.net WMI 复制文件”或“.net WMI 执行文件”对我根本没有帮助。
任何参考将不胜感激。
编辑
我无法使用 PsExec 等第三方工具(尽管它完全满足我的需要)。这是因为 PsExec 涉及许可证,我无法将其与我的应用程序一起分发。
I'm using .NET, and going crazy trying to find any helpful API that lets me transfer a file across a LAN network (trough admin credentials of course) and then execute it on that machine.
I've read some thing using WMI, but googling for ".net WMI copy files" or ".net WMI execute files" isn't helping me at all.
Any references would be greatly appreciated.
EDIT
I can't use a third party tool such as PsExec (although it does perfectly what I need). This is because of the license involved with PsExec I cannot distribute it with my application.
发布评论
评论(4)
我知道已经过去很多年了,但遇到了这个挑战并看到了这篇文章(以及其他文章),因此我将分享解决方案,以防它可以帮助任何人前进。它可用于通过 WMI 移动任何您想要的文件。
解决方案:
1:将 EXE 转换为 Base64
2:通过 WMI 将 Base64 回显为文件并使用 certutil 进行解码
现在,有一些问题需要突出显示
就我而言,我不想一次发送 7000 个字符的完整 2MB 文件,因此我创建了一个简单的 .net 下载器,该下载器编译为小于 6KB,并将其全部放入单个语句中(如上所述)。下载我的可执行文件,完成后(当我看到我想要的文件时,通过 WMI 查询)我只需通过 WMI 删除它。
I know it's been years, but ran into this challenge and came accross this post (among others) so going to share the solution in case it helps anyone moving forward. It can be used to move any file you want over WMI.
Solution:
1: Convert EXE to Base64
2: Echo Base64 to a file over WMI and decode with certutil
Now, there are some gotcha's that need to be highlighted
In my case, I didn't want to send a full 2MB file 7000 characters at a time, so I created a simple .net downloader that compiled to less than 6KB and got it all into a single statement (as per above.) It downloads my executable and when complete (when I see the file I want, queried over WMI) I just delete it over WMI.
我认为这并不容易实现。不过,您可以使用 .net 复制 exe。然后(同样来自 .net,使用
Process.Start
)调用 psExec 并使其远程执行程序。I don't think that this is easily achieved. You can however copy the exe with .net. And then (also from .net, with
Process.Start
) invoke psExec and make it execute the program remotely.在没有 PowerShell 2.0 远程处理已启用,我发现 PsExec 命令行工具非常有用。它需要远程计算机上的管理权限。
On machines that don't have PowerShell 2.0 remoting enabled, I find the PsExec commandline tool very useful. It requires administration permissions on the remote machine.
您可以考虑使用Scheduler服务(AT命令)来启动应用程序(参见http://msdn.microsoft.com/en-us/library/aa384006.aspx) 将应用程序代码复制到远程计算机后。
You can consider to use Scheduler service (AT command) to start an application (see http://msdn.microsoft.com/en-us/library/aa384006.aspx) after the application code are copied to the remote computer.