返回首页

下面提供的代码发布,也给我提供的代码。
我改变,例如规定代码的代码。
但也有出现另一个错误消息即(访问路径"\ \ 192.168.1.10 \ C $ \右"被拒绝),但我的txt文件共享。
chaging代码如下。

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

我的上述问题有任何解决方案????
请提供正确的代码...
我等待答复.....:7678194 |会员

回答

评论会员:游客 时间:2012/02/06
要访问元,你必须在目标计算机上的管理员
约翰・西蒙斯/取缔程序员
评论会员:游客 时间:2012/02/06
如果远程机器是Vista或Windows7,你可以不写到C盘的文件,除非你有那台机器上的管理员帐户:会员7678194:根据提供您的代码访问C$你必须在目标计算机上的管理员"但没有本地节点上的用户名和密码,M/C和服务器相同M/C我发布的问题,我怎样才能解决??请提供信息。我等待正确的方式......