2016-11-11 113 views
0

我已经创建了一个程序,它将从我的计算机复制到其他远程计算机的特定文件。我已经成功地做到了这一点,但只在驱动程序C:\中。我的问题是如何将文件复制到D:\驱动器?将文件复制到远程计算机

我已经尝试加入\ 157.60.113.28 \ D:\ testnew \ right.bmp但没有运气。让我知道!

Imports System 
Imports System.Runtime.InteropServices 
Imports System.Security.Principal 
Imports System.Security.Permissions 
Public Class Form1 
<DllImport("advapi32.DLL", SetLastError:=True)> _ 
Public Shared Function LogonUser(ByVal lpszUsername As String, ByVal lpszDomain As String, _ 
    ByVal lpszPassword As String, ByVal dwLogonType As Integer, ByVal dwLogonProvider As Integer, _ 
    ByRef phToken As IntPtr) As Integer 
End Function 
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 
    Dim admin_token As IntPtr 
    Dim wid_current As WindowsIdentity = WindowsIdentity.GetCurrent() 
    Dim wid_admin As WindowsIdentity = Nothing 
    Dim wic As WindowsImpersonationContext = Nothing 
    Try 
     MessageBox.Show("Copying file...") 
     If LogonUser("Local Admin name", "Local computer name", "pwd", 9, 0, admin_token) <> 0 Then 
      wid_admin = New WindowsIdentity(admin_token) 
      wic = wid_admin.Impersonate() 
      System.IO.File.Copy("C:\right.bmp", "\\157.60.113.28\testnew\right.bmp", True) 
      MessageBox.Show("Copy succeeded") 
     Else 
      MessageBox.Show("Copy Failed") 
     End If 
    Catch se As System.Exception 
     Dim ret As Integer = Marshal.GetLastWin32Error() 
     MessageBox.Show(ret.ToString(), "Error code: " + ret.ToString()) 
     MessageBox.Show(se.Message) 
    Finally 
     If wic IsNot Nothing Then 
      wic.Undo() 
     End If 
    End Try 
End Sub 
End Class 

回答

0

你正在寻找的路径是:

\\157.60.113.28\D$\testnew\right.bmp 

如果您需要与远程机器交互定期会是明智的网络路径映射在你的机器的网络驱动器。

mapping network drive

+0

Haleluia!非常感谢你。 –

+0

@RobertKodra如果它解决了您的问题,请在答案左侧标记V以显示您的感激之情。 – Stavm

+1

当然我会说,我需要等3分钟才能接受答案。感谢您的帮助和提示! –

相关问题