Home All Groups Group Topic Archive Search About

CFileDialog and ImpersonateLoggedOnUser on Win2k system

Author
7 Mar 2005 7:39 PM
Jijo Dominic via .NET 247
Hello there,
I am facing a problem with CFileDialog and ImpersonateLoggedOnUser on Win2k system. I wrote a small program to run on Win2k, after starting the application from Non-Adminstrator account, can run and open some administrator restricted files after giving Adimistrator user name and password. For that I use ImpersonateLoggedOnUser. But CFileDialog fuction fails when you login using administrator account. Any Idea why this is happening. here is how I used these calls:

HANDLE hToken;
BOOL ret = LogonUser((char *)((const char *)m_sUsername), ".", (char *)((const char *)m_sPassword), LOGON32_LOGON_BATCH, LOGON32_PROVIDER_DEFAULT, &hToken);
if(!ret)
{
   AfxMessageBox("test", MB_OK|MB_ICONWARNING);
   return;
}
else {
  ImpersonateLoggedOnUser(hToken);
}
CFileDialog OpenDlg(TRUE, NULL, NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,
                   NULL, NULL);
if(OpenDlg.DoModal()== IDOK){
   file=ppdOpenDlg.GetFileName();
}

One widows 2000 system, this OpenDlg.DoModal() fails with return value 2, which says " system can not open the specified file".
Did anybody face this problem? Any type of help is highly appriciated.
Thanks in advance
Jijo

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>D50dyapCZkmih2sRGKSdTQ==</Id>