Advertisement

02.11.2008 at 11:36AM PST, ID: 23154081
[x]
Attachment Details

Impersonate user for file read/write on network share

Asked by JonMny in C# Programming Language, .NET

Tags: c#, Windows forms Application

I am having trouble getting the logon user function to work. I am attempting to access a share on a network computer.  The account I am using is a local account on the manchine - Not a domain account.  If I use the logon_new_credentials, the login succeeds but the createdirectory returns bad user/password



IntPtr lnToken;
       
     //   LOGON32_LOGON_NEW_CREDENTIALS - Using this the logon succeeds but the create directory still returns bad username/ passord
        int TResult = LogonUser(@"remotecomputer\adminuser", "RemoteComputer", "password", LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, out lnToken);
        Win32Exception e = new Win32Exception();
        string x =e.Message;
        if ( TResult > 0 )
            {
 
           ImpersonateLoggedOnUser(lnToken);
           using( WindowsIdentity.Impersonate(lnToken))
           {

               Directory.CreateDirectory("\\\\remotecomputer\\ShareedFolder\\Test");

           }
           
                  StringBuilder sb = new StringBuilder(80,80);
                  RevertToSelf();
                  CloseHandle(lnToken);
            }
            else
            {
                  
            }


            return;
Start Free Trial
 
Loading Advertisement...
 
[+][-]02.11.2008 at 04:28PM PST, ID: 20871656

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: C# Programming Language, .NET
Tags: c#, Windows forms Application
Sign Up Now!
Solution Provided By: topdog770
Participating Experts: 1
Solution Grade: B
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628