長話短說,我的應用程序需要將文件複製到遠程目標,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沒有工作?還是有人有更好的方式做我想做的事情?