如何实现远程执行了一个dos命令,并把结果返回显示在一个listbox上

squall_sw 2008-01-23 03:50:29


我现在使用的是WMI连接,这是代码,命令也已经在远程执行了,但是我怎么获取到这个命令的结果,并且把所有命令的结果显示在listbox上呢?

Dim options As New ConnectionOption

Dim _scope as ManagementScope
options.Username = “aaa“

options.Password = "aaaa"

options.Authority = "ntlmdomain:strdomain"
If strdomain Is Nothing Then
_scope = New ManagementScope("\\" 10.0.0.1 "\root\cimv2", options)
_scope.Connect()
Else
options.Authority = "ntlmdomain:strdomain"
_scope = New ManagementScope("\\" 10.0.0.1 "\root\cimv2", options)
_scope.Connect()
End If

Dim o As New ObjectGetOptions()
Dim path As ManagementPath = New ManagementPath("Win32_Process")
Dim processClass As ManagementClass = New ManagementClass(_scope, path, o)
Dim inParams As ManagementBaseObject = processClass.GetMethodParameters("Create")
Dim a As ManagementObject
Dim b As String
b = Nothing
inParams("CommandLine") = "cmd.exe /c netstat -an"
...全文
154 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
llsus 2008-01-23
  • 打赏
  • 举报
回复
别的我就不会了,我没弄过这东西。
squall_sw 2008-01-23
  • 打赏
  • 举报
回复
我也是这么想的,但是这个方法我觉得怪怪的,请问有没有更好的办法呢?
llsus 2008-01-23
  • 打赏
  • 举报
回复
我提供你的一个比较土的方法,你没有更好的办法之前可以考虑使用
就是把执行结果重定向到一个文件中,然后再读取那个文件你总会吧
例如要执行:dir c:\ 默认会显示在屏幕上,你可以把命令写成 dir c:\ > c:\Result.txt 就可以把本来该显示在屏幕上的内容存在文件中了,你只要读取远程主机上的C:\Result.txt显示在自己的listbox中就可以了,然后再删除那个Result.txt文件即可。
it_gz_xi 2008-01-23
  • 打赏
  • 举报
回复
UP

16,722

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧