长话短说,我的应用程序需要将文件复制到远程目标,UNC可能无法连接到目标。但是,从目标和BACK到服务器的UNC连接始终是可能的。所以计划是使用WMI启动远程命令外壳(cmd)并使用copy命令来获取文件。但这不起作用。当距离目标的命令行手动执行下面的命令正常工作:WMI远程进程复制文件
copy \\192.168.100.12\c$\remotefile.txt c:\localfile.txt
但当我尝试这个相同的命令作为InputParameters("CommandLine")
的一部分,这是行不通的,并且不产生错误。请注意,我可以使用WMI连接到目标,并远程执行工作就好了,我可以开始的calc.exe等。这里是不起作用的代码:
Dim ConnectionOptions As New System.Management.ConnectionOptions
With ConnectionOptions
.Username = "target\Administrator"
.Password = "password"
End With
Dim ManagementScope As New System.Management.ManagementScope("\\192.168.100.11\root\cimv2", ConnectionOptions)
Try
ManagementScope.Connect()
MsgBox("connected")
Dim ManagementPath As New System.Management.ManagementPath("Win32_Process")
Dim ManagementOptions As New System.Management.ObjectGetOptions
Dim ManagementClass As New System.Management.ManagementClass(ManagementScope, ManagementPath, ManagementOptions)
Dim InputParameters As System.Management.ManagementBaseObject = ManagementClass.GetMethodParameters("Create")
InputParameters("CommandLine") = "cmd /c copy \\192.168.100.12\c$\remotefile.txt c:\localfile.txt"
Dim OutputParameters As System.Management.ManagementBaseObject = ManagementClass.InvokeMethod("Create", InputParameters, Nothing)
MsgBox("done")
Catch ex As Exception
MsgBox(ex.Message)
End Try
任何想法,为什么这个ISN没有工作?还是有人有更好的方式做我想做的事情?