0

I have a WindowsForms vb.net Framework 4.6 Application which must copy some files from c:\sample to a network drive (\\servername\sample).

I must use other credentials to access the share. But I can't use impersonate, because i have to use a local user on the Server. The Login on the server is something like <.\Username> <password>.

Is there a way to copy my files to the network drive using the server's local user credentials?

EDIT 18.06:

I also tried this way, but it did not work for me.

        Dim domain, username, passwordStr, remoteServerName As String
        Dim password As New System.Security.SecureString
        Dim command As New Process

        domain = "servername"
        username = "username"
        passwordStr = "password"
        remoteServerName = "\\servername\path\"
        Dim impersonator As New AliasAccount(username, passwordStr)

        For Each c As Char In passwordStr.ToCharArray
            password.AppendChar(c)
        Next

        command.StartInfo.FileName = "test.pdf"
        command.StartInfo.Arguments = remoteServerName

        command.StartInfo.UserName = username
        command.StartInfo.Password = password
        command.StartInfo.Domain = domain
        command.StartInfo.Verb = "open"
        command.StartInfo.UseShellExecute = False

        impersonator.BeginImpersonation()
        command.Start()
        impersonator.EndImpersonation()

My user on the server does not a have a specific domain, because the user only exists on the server. So i'm using the servername as the domain. I also tried using ".\".

I'm always getting the same error "wrong username or password" (translated from german to englisch). I've checked the username and password more than 30 times... It is definitely correct. I'm also able to connect a network drive with the credentials... So they are correct.

Do you have any other suggestions?

querentin
  • 1
  • 1
  • 1
    Could you maybe expand a little on the problem you are trying to solve here. From my perspective this is normally as the result of poor network design, or tying to fix problems that don't exist. Historically when in this situation, I've done something via netuse to create a mapped drive to the server location which simplifies the authentication problem. Probably cleaner solutions, but it works for me – Hursey Jun 16 '21 at 21:33
  • 1
    Does this answer your question? [Open remote shared folder with credentials](https://stackoverflow.com/questions/7559867/open-remote-shared-folder-with-credentials) – BDL Jun 18 '21 at 09:36
  • Did you see this answer? https://stackoverflow.com/questions/7559867/open-remote-shared-folder-with-credentials This works for me for since years. – Chris Berlin Jun 17 '21 at 07:13
  • @ChrisBerlin thanks for your suggestions. I tried it this way an edited my Question. It does not work for me. I'm always getting "Wrong username or password". But i'm using the correct credentials, I'm able to connect a network drive with my creds. I think my problem is about the local user on server which i'm trying to impersonate on my local pc. – querentin Jun 28 '21 at 08:49
  • @BDL thanks for your suggestion, too. ChrisBerlin gave me the same hint. Please reade my comment to ChrisBerlin's answer – querentin Jun 28 '21 at 08:51
  • @Hursey I've edited my question. Does it make that more clearly to you? I'm already using impersonation to save files to my server. So far i was using a domain joined user for my impersonation. But now i have to use a local user account which only exists on my fileserver. Is it possible to use a local server user for impersonation? – querentin Jun 28 '21 at 08:56

0 Answers0