Click to See Complete Forum and Search --> : Problem in while creating file on web server through ATL COM function


vaibhavPawar
September 4th, 2007, 11:55 AM
I've to create one API function using ATL COM and I Want to add reference in C#.net but i m getting one problem while creating file on file / web server through ATL COM function . also I am Impersonate the user then after try to create file on the server but still file is not created on the file server . so pls help me how to copy files through ATL COM function on WEB Server .


My Code Is :

STDMETHODIMP CDataSecurity::CreateKeyRingFile()

{

HANDLE handle ;

HANDLE hToken2;

SECURITY_IMPERSONATION_LEVEL sil = SecurityImpersonation;

HANDLE hFile;

BOOL bSuccess = false;

HANDLE hLogonToken = 0;

bSuccess = LogonUser("workterrauser", "harbinger.com","woRktErra!007",9,LOGON32_PROVIDER_DEFAULT, &hLogonToken );

if ( bSuccess )

bSuccess = ImpersonateLoggedOnUser( hLogonToken );

if ( bSuccess )

// bSuccess = DuplicateTokenEx( hLogonToken, MAXIMUM_ALLOWED, 0,

//SecurityImpersonation, TokenPrimary, &hToken2 );

bSuccess = DuplicateToken( hLogonToken, SecurityImpersonation,&hToken2 );

if ( bSuccess )

hFile = CreateFile("\\192.168.2.210\\OnlineEnrollmentSystem\\Temp\\xxx.dat", GENERIC_WRITE, FILE_SHARE_WRITE,

NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);

// return (hImpersonationToken);

fclose(fp);

return S_OK;

}

UnderDog
September 5th, 2007, 08:35 AM
Advise - Learn about GetLastErrorCode and learn how to interpret the error codes that it returns.