DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Application act as another user

  1. #1
    Join Date
    Dec 2003

    Permissions on Files

    The simple question is:
    How can I create an identity so the application can use that identity to access the folder on a differnet computer to get files.

    The domain is Win2K this is a DOTNET applcation but the installs are VB6.

    I have an application that needs to check the current version of an application if the application is not the same version uninstall the application and install the new application. This works but the last piece is the install directory is only open to a singel user name and password. The user running this application does not have access to the folder. The reason the install are so tighly secured is some of them have business rules that some users are not allowed to use.

  2. #2
    Join Date
    Dec 2003

    Solved part of the question

    I figured out that I need to Crate and new thread under the context of the id with access to the folder.

    All works fine until I try to access the folder out on the share. I get an error saying file not found.

    here is the sample code

    Dim th As System.Threading.Thread
    Dim wp As System.Security.Principal.WindowsPrincipal
    Dim Domain As String = "domain"
    Dim sPassword As String = "password"
    Dim sUser As String = "user"
    wp = New System.Security.Principal.WindowsPrincipal(ClientDomain.NetworkIO.NetworkSecurity.getIdent ity(Domain, sUser, sPassword, ClientDomain.NetworkIO.LogonType.LOGON32_LOGON_NETWORK, ClientDomain.NetworkIO.LogonProvider.LOGON32_PROVIDER_DEFAULT))

    th = New System.Threading.Thread(AddressOf HandleExecutable)
    th.CurrentPrincipal = wp

    function HandleExecutable

    --This line cause the error
    System.IO.File.Copy(mApp.AppInstall, mApp.CompleteFileName, True)

    end function

  3. #3
    Join Date
    Dec 2003

    Application act as another user

    How do I get the application to act as another user.

    I am user 'A' how do I get the Application to run as user 'B'. User 'B' has rights to shared folders on the network that user 'A' does not. so for a time I need to act as user 'B' to copy the files local.

    Here is what I have.

    Dim wp As System.Security.Principal.WindowsPrincipal
    Dim Domain As String = "ITFirst-HQ"
    Dim sPassword As String = "password"
    Dim sUser As String = "vsecure"
    Dim wi As WindowsImpersonationContext
    wi = NetworkSecurity.ImpersonateUser(Domain, sUser, sPassword, LogonType.LOGON32_LOGON_NETWORK, LogonProvider.LOGON32_PROVIDER_DEFAULT, True)

    wp = New WindowsPrincipal(NetworkSecurity.getIdentity(Domain, sUser, sPassword, LogonType.LOGON32_LOGON_NETWORK, LogonProvider.LOGON32_PROVIDER_DEFAULT, True))


    Dim th As Threading.Thread = New Threading.Thread(AddressOf CopyFile)

    Private Sub CopyFile()
    Dim th As Threading.Thread = System.Threading.Thread.CurrentThread
    Dim wp As WindowsPrincipal = th.CurrentPrincipal
    Dim id As WindowsIdentity = wp.Identity
    System.IO.File.Copy("\\server\SecureTest\test.pdf", "C:\test.pdf", True)
    End Sub

  4. #4
    Join Date
    Dec 2003
    The method I've seen implemented requires the LogonUser API function call:

    WindowsImpersonationContext Class
    Microsoft MVP (Visual Basic)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center