#1
  1. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Aug 2005
    Posts
    2
    Rep Power
    0

    Unhappy Security Exception: 0x800A0046 (CTL_E_PERMISSIONDENIED)


    Hello,
    I am trying to copy a file to a shared folder on a remote computer.
    I am using vb.net 2005 and windows xp.
    I created the neccesary user accounts on each computer and set up the required permissions but i keep getting
    SecurityException was Unhandled
    Exception from HRESULT: 0x800A0046(CTL_E_PERMISSIONDENIED)

    When i try to access the shared folder manually using the windows browser and copy files to it it works fine, but it give the above error when i use the vb code.

    I tried impersonating the user, but even though it says that the impersonation is successful i still get the same error.

    The error happens when executing the line:
    fso.CopyFile(TextBox1.Text, "\\" & IP & "\Documents", True)


    Help would be much appreciated
    I really tried everything and i don't know what to do next.

    I attached some of the code I am using below:

    Thank you


    Declare Function LogonUserA Lib "advapi32.dll" (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

    Declare Auto Function DuplicateToken Lib "advapi32.dll" ( _
    ByVal ExistingTokenHandle As IntPtr, _
    ByVal ImpersonationLevel As Integer, _
    ByRef DuplicateTokenHandle As IntPtr) As Integer

    Declare Auto Function RevertToSelf Lib "advapi32.dll" () As Long
    Declare Auto Function CloseHandle Lib "kernel32.dll" (ByVal handle As IntPtr) As Long

    'Private Const LOGON32_LOGON_NETWORK As Integer = 3
    Private Const LOGON32_LOGON_INTERACTIVE As Integer = 2
    Private Const LOGON32_PROVIDER_DEFAULT As Integer = 0
    Private Function impersonateValidUser(ByVal userName As String, _
    ByVal domain As String, ByVal password As String) As Boolean

    Dim tempWindowsIdentity As WindowsIdentity
    Dim token As IntPtr = IntPtr.Zero
    Dim tokenDuplicate As IntPtr = IntPtr.Zero
    impersonateValidUser = False

    If RevertToSelf() Then
    If LogonUserA(userName, domain, password, LOGON32_LOGON_INTERACTIVE, _
    LOGON32_PROVIDER_DEFAULT, token) <> 0 Then
    If DuplicateToken(token, 2, tokenDuplicate) <> 0 Then
    tempWindowsIdentity = New WindowsIdentity(tokenDuplicate)
    impersonationContext = tempWindowsIdentity.Impersonate()
    If Not impersonationContext Is Nothing Then
    impersonateValidUser = True
    End If
    End If
    End If
    End If
    If Not tokenDuplicate.Equals(IntPtr.Zero) Then
    CloseHandle(tokenDuplicate)
    End If
    If Not token.Equals(IntPtr.Zero) Then
    CloseHandle(token)
    End If
    End Function

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    'On Error Resume Next
    Dim fso As Object
    Dim IP As String
    If TextBox1.Text = "" Then
    MsgBox("Please select a file.")
    End If
    If TextBox2.Text = "" Then
    MsgBox("Please enter an IP address.")
    End If
    IP = TextBox2.Text
    fso = CreateObject("Scripting.FileSystemObject")

    If impersonateValidUser("Username", ".", "Password") Then
    MsgBox("Impersonation successful")
    fso.CopyFile(TextBox1.Text, "\\" & IP & "\Documents", True)
    undoImpersonation()
    Else
    'Your impersonation failed. Therefore, include a fail-safe mechanism here.
    MsgBox("Impersonation failed")
    End If

    'call the client application

    'Shell("cmd /c" & "psexec \\" & IP & " " & "-i " & "c:\media_transfer\media_transfer_client_applicati on\media_transfer_client_application\bin\media_tra nsfer_client_application.exe")

    MsgBox("File copied successfully on: " & IP, vbOKOnly, "Media Transfer Prototype")
    End Sub
    Private Sub undoImpersonation()
    impersonationContext.Undo()
    End Sub
  2. #2
  3. Contributing User
    ASP Adventurer (500 - 999 posts)

    Join Date
    Dec 2003
    Location
    India
    Posts
    698
    Rep Power
    106

    Exclamation Sorry Didn't look at your code in depth.....


    Sorry Didn't look at your code in depth.
    but it seemd that you are having some file manipulations from one folder to another on network.
    If yes then assure that
    Your server admin will have to grant write permissions for the IIS user account in the target folder.
    Also have a look at
    Security Issue
    Last edited by master_key; August 3rd, 2005 at 04:39 AM.

    ASP.NET Geeks
    Visit this group
  4. #3
  5. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Aug 2005
    Posts
    2
    Rep Power
    0
    Thank you very much for your reply.

    I had a look at the link you provided, I already run the process under an account known on both servers and that also has the appropriate file and share level permissions, that's why I don't understand why is it still complaining about security problems.
    As I mentioned before i tried to impersonnate the user, and although it says the impersonnation was successful, it still throws a security error.

    Do you have any suggestions for me please?

    Thank you

Similar Threads

  1. Replies: 2
    Last Post: January 29th, 2005, 05:25 PM
  2. Windows Host Security: Network Security Hacks
    By DevAdmin in forum Development Articles
    Replies: 0
    Last Post: September 20th, 2004, 09:00 AM
  3. The Server Threw an Exception (doc2pdf)
    By Omicron in forum .NET Development
    Replies: 1
    Last Post: February 12th, 2004, 04:26 PM
  4. Security exception
    By kyledunn in forum .NET Development
    Replies: 0
    Last Post: May 29th, 2003, 11:31 PM
  5. Security Exception when running ASP.NET Web Application
    By Steve Schofield in forum .NET Development
    Replies: 0
    Last Post: May 24th, 2002, 02:38 AM

IMN logo majestic logo threadwatch logo seochat tools logo