BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

LogonUser + SHBrowseForFolder Problem

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (WinAPI)
View previous topic :: View next topic  
Author Message
Guest






PostPosted: Tue May 23, 2006 10:14 am    Post subject: LogonUser + SHBrowseForFolder Problem Reply with quote



Hi,

I've got a function that tries to select a directory under a network
shared folder. Here is what I did :

bool __fastcall BrowseForFolder(WideString Title, WideString &Path)
{

BROWSEINFO BrowsingInfo;
wchar_t DirPath[MAX_PATH];
LPITEMIDLIST ItemID;

memset(&BrowsingInfo, 0, sizeof(BROWSEINFO));
memset(DirPath, 0, MAX_PATH);
BrowsingInfo.hwndOwner = GetActiveWindow();
BrowsingInfo.lpszTitle = Title.c_bstr();
BrowsingInfo.ulFlags |= BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS
| BIF_SHAREABLE | BIF_USENEWUI | BIF_BROWSEINCLUDEFILES |
BIF_BROWSEINCLUDEURLS ;

if(Path != NULL)
{
// namespace root for parsing the path
LPSHELLFOLDER psfDesktop = NULL;
SHGetDesktopFolder(&psfDesktop);
// parse path for absolute PIDL, and connect to target folder
LPITEMIDLIST pidl = NULL; // general purpose
psfDesktop->ParseDisplayName(NULL, NULL, Path.c_bstr(), NULL, &pidl,
NULL);
BrowsingInfo.pidlRoot = pidl;
}
CoInitialize(NULL);
ItemID = SHBrowseForFolder(&BrowsingInfo);
if(ItemID)
{
SHGetPathFromIDList(ItemID, DirPath);
Path=WideString(DirPath);
}
GlobalFreePtr(ItemID);
return 0!=ItemID;

}


void main(void)
{
WideString Directory;

HANDLE token;
if(LogonUser(EditLogin->Text.c_bstr(), L"\\\\192.168.0.2",
EditPassword->Text.c_bstr(),
LOGON32_LOGON_NEW_CREDENTIALS,
LOGON32_PROVIDER_DEFAULT,
&token))
{
if(ImpersonateLoggedOnUser(token))
{
Directory = "\\\\192.168.0.2\\directory1\\subdirectory";
if(BrowseForFolder(WideString("Please select the directory"),
Directory))
EditServerPath->Text = Directory;

RevertToSelf();
}
CloseHandle(token);
}
else
MessageDlg("Impossible to connect to Server !", mtWarning,
TMsgDlgButtons() << mbOK, 0);
}

My problem is that it succeeds to show the directory
\\\\192.168.0.2\\directory1\\subdirectory, but I can't see anything
under it (neither subdirectories, nor files). What am I doing wrong ?

Further more, if I log onto the server with an explorer, and than I try
to launch my code, It succeeds in listing all the subdirectories and
files under de path !

Has anyone encountered such problems ?

Thanks a lot for your attention.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (WinAPI) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.