2016-11-11 120 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分鐘才能接受答案。感謝您的幫助和提示! –

相關問題