Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Below giving code posted and also provided code to me.
I change the code as like prescribed code.
But there is arise another error message i.e.(Access to path '\\192.168.1.10\c$\right' is denied) yet my txt file is shared.
The chaging code is below.


VB
Imports System
Imports System.Runtime.InteropServices
Imports System.Security.Principal
Imports System.Security.Permissions
Public Class Form1
    <dllimport("advapi32.dll",> _
    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
            If LogonUser("SNEHASIS\Administrator", "SNEHASIS", "", 9, 0, admin_token) <> 0 Then
                wid_admin = New WindowsIdentity(admin_token)
                wic = wid_admin.Impersonate()
                System.IO.File.Copy("C:\file.txt", "\\192.168.1.10\c$\right.txt", True) ''157.60.113.28
                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


Have any solution for my above problem??????
Please supply right code ...
I wait for reply.....
Posted
Updated 21-Sep-11 23:48pm
v2

To access the C$ you have to be an administrator on the target machine.
 
Share this answer
 
If the remote machine is Vista or Windows 7, you can't write files to the C drive unless you have an administrator account on that machine.
 
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