我正在尝试将local text file
工作目录中的一个复制到其他目录remote desktop
这就是我在这里提到的尝试方法
ExecuteCommand("Copy" & Directory.GetCurrentDirectory & "\Output\Files.txt \\myservername -u username -p password C$\Files.txt")
Public Sub ExecuteCommand(ByVal Command As String)
Dim ProcessInfo As ProcessStartInfo
Dim Process As Process
ProcessInfo = New ProcessStartInfo("cmd.exe", "/K" & Command)
ProcessInfo.CreateNoWindow = True
ProcessInfo.UseShellExecute = True
Process = Process.Start(ProcessInfo)
End Sub
我收到此错误:
The filename, directory name or volume label syntax is incorrect
好吧,首先,您在“复制”之后缺少空格:
ExecuteCommand("Copy" & Directory.GetCurrentDirectory & ...
将会变成(假设当前目录为“ C:\ MYDIR”)
cmd.exe /kCopyC:\MYDIR
/k
选项后面没有空格cmd.exe
不是问题,但是看起来很尴尬。我也要在那里放一个。
第二,"\\myservername -u username -p password C$\Files.txt"
看起来是错误的。那可能应该"\\myservername\C$\Files.txt"
遵循您的示例。用户名和密码在此时和Copy
命令上下文中没有任何意义(复制过去的错误?)。
然后,在您的问题的“ ExecuteCommand ...”示例中有一些假冒(?)换行符。可能是这些问题引起了更多问题,但就目前情况而言,这很难说出来。
Command
在您的ExecuteCommand
方法中输出变量的值(或使用调试器),然后检查其是否正确。另外,请尝试首先从命令行执行整个操作,以确保其正常工作。
放在一起,我会这样写:
ExecuteCommand("Copy " & Directory.GetCurrentDirectory & "\Output\Files.txt \\myservername\C$\Files.txt")
' ...
Public Sub ExecuteCommand(ByVal Command As String)
Dim ProcessInfo As ProcessStartInfo
Dim Process As Process
ProcessInfo = New ProcessStartInfo("cmd.exe", "/K " & Command)
ProcessInfo.CreateNoWindow = True
ProcessInfo.UseShellExecute = True
Process = Process.Start(ProcessInfo)
' You might want to wait for the copy operation to actually finish.
Process.WaitForExit()
' You might want to check the success of the operation looking at
' Process.ExitCode, which should be 0 when all is good (in this case).
Process.Dispose()
End Sub
最后,您可能只是使用了File.Copy
。无需cmd.exe
为此:
File.Copy(Directory.GetCurrentDirectory & "\Output\Files.txt",
"\\myservername\C$\Files.txt")
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句