2013-08-23 64 views
0

我试图复制local text file这是我的工作目录到其他remote desktop复制本地文本文件到远程桌面

这是我试图做提到的方式here

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 

我GETT荷兰国际集团这样的错误:

The filename, directory name or volume label syntax is incorrect

回答

1

嗯,首先,你缺少的 “复制” 后面输入一个空格:

ExecuteCommand("Copy" & Directory.GetCurrentDirectory & ... 

,将变成(鉴于当前目录以“C:\ MYDIR”为例)

cmd.exe /kCopyC:\MYDIR 

缺少空间af ter /k选项cmd.exe不是问题,但看起来很尴尬。我也会在那里放一个。

其次,"\\myservername -u username -p password C$\Files.txt"看起来错了。你的例子可能应该是"\\myservername\C$\Files.txt"。用户名和密码在这一点和Copy命令(复制过去错误?)的上下文中没有意义。

然后你在你的问题的“ExecuteCommand ...”例子中有一些虚假(?)行包装。可能是因为这些问题导致了更多的问题,但这很难说明问题。

ExecuteCommand方法(或使用调试器)中输出Command变量的值并检查它是否正常。另外,首先尝试从命令行执行整个事情以确保它能够正常工作。

全部放在一起,我会写这样的:

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") 
+0

@ Christian.K-首先感谢您的详细解释,如果我使用上述语法File.Copy(...)它给了我和错误,指出“登录失败..Bad用户名或密码“,但能够使用相同的用户名和密码打开远程桌面。 – coder

+0

您需要确保用户(最终运行'File.Copy'或您的'ExecuteCommand')实际上具有对目标(即\\ myservername \ c $ \')的写访问权限。 –

+0

我正在使用file.copy,并且我刚刚检查了“C $”..它具有完整的读写和执行权限。 – coder

相关问题