Click here to Skip to main content
15,898,373 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
Imports System.Net
Imports System.IO
Public Class Form6

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            
            Dim FileToCopy As String
            Dim NewCopy As String
            Dim password As String = "208145"
            Dim username As String = "AB208145"
          

            FileToCopy = "\\192.168.10.03\C$\HRIS.exe" & username & ":'" & password
            NewCopy = "C:\HRIS.exe"

            If System.IO.File.Exists(FileToCopy) = False Then
                TextBox1.Text = "HRIS.exe"
                System.IO.File.Copy(NewCopy, FileToCopy)
                MsgBox("File Copied")
            Else
                MsgBox("cannot copy")
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub
    
End Class
Posted
Updated 22-Mar-14 20:39pm
v2

You have to be an admin on the destination machine to use the C$ drive shares, and you have to authenticate first before copying.

You are better off creating a normal share on that machine with permissions you can control.
 
Share this answer
 
Comments
khei-chan007 23-Mar-14 2:56am    
c: not working either. how can i do authentication? i'm new in vb.net so i don't know much.
Mehdi Gholam 23-Mar-14 3:01am    
Read this : http://stackoverflow.com/questions/295538/how-to-provide-user-name-and-password-when-connecting-to-a-network-share
Do you have access to this path? Try browsing the path from your machine.
 
Share this answer
 
Comments
khei-chan007 24-Mar-14 8:31am    
i can log-in in the 192.168.10.03 through my computer, my database was save in 192.168.10.03.
Hi guys, thanks for your help. At last I already solve my problem.. :) Here's the new and working codes.
<br />
Public Class Form6<br />
<br />
 <runtime.interopservices.dllimport("advapi32.dll",> _<br />
    Public Shared Function LogonUser(ByVal lpszUsername As String, ByVal lpszDomain As String, _<br />
         ByVal lpszPassword As String, ByVal dwLogonType As Integer, ByVal dwLogonProvider As Integer, _<br />
         ByRef phToken As IntPtr) As Integer<br />
    End Function<br />
<br />
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click<br />
<br />
        Dim sToken As IntPtr<br />
        Dim impersonatedUser As Principal.WindowsImpersonationContext = Nothing<br />
        Dim wid_current As WindowsIdentity = WindowsIdentity.GetCurrent()<br />
        Dim wid_admin As WindowsIdentity = Nothing<br />
        Dim wic As WindowsImpersonationContext = Nothing<br />
        Try<br />
            MessageBox.Show("Copying file...")<br />
            ' ''-------If LogonUser("Username", "computer name of 192.168.10.03", "passwordd", 9, 0, sToken) <> 0 Then ---------'' '<br />
            <br />
            If LogonUser("AB208145", "PROD-PC", "208145", 9, 0, sToken) <> 0 Then<br />
                wid_admin = New WindowsIdentity(sToken)<br />
                wic = wid_admin.Impersonate()<br />
                ' ''-------("\\IP add\shared folder\file to be copy),(my drive c:\copy file)------------'' '<br />
                System.IO.File.Copy("\\192.168.10.03\sample01\HRIS.exe", "C:\HRIS.exe", True)<br />
<br />
                MessageBox.Show("Copy succeeded")<br />
            Else<br />
                MessageBox.Show("Copy Failed")<br />
<br />
            End If<br />
        Catch se As System.Exception<br />
            Dim ret As Integer = Marshal.GetLastWin32Error()<br />
            MessageBox.Show(ret.ToString(), "Error code: " + ret.ToString())<br />
            MessageBox.Show(se.Message)<br />
        Finally<br />
            If wic IsNot Nothing Then<br />
                wic.Undo()<br />
            End If<br />
        End Try<br />
  End Sub<br />
End Class<br />
 
Share this answer
 
For Permission your network path

select your folder-> right click ->Properties ->Sharing->Advance Sharing->check to share this folder ->permission ->if "everyone" user is there then ok other wise you have to add it

To add Click add ->Advance -> Find Now ->Select Everyone ->Ok -> Ok Check on Full Control Apply

now security

go to security tab -> If Everyone is there then ok other wise you have to add

Go to edit -click add and all same as above

after add check on full control -> Apply ->Ok

permission is granted now can use your path from any where from any user
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900