Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

GetFileAttributes not working for mapped network directories

656 views
Skip to first unread message

Terence Wilson

unread,
Dec 16, 1997, 3:00:00 AM12/16/97
to

I am using GetFileAttributes to determine the presence of a directory.
However, I am finding that if the user has mapped a network directory
to a local drive letter, e.g. l:, GetFileAttributes("l:") returns
0xFFFFFFFFF which is classified as a failure.

Further investigation using GetLastError and FormatMessage
revealed the error string to be something like "username unknown or
password incorrect". I should point out that both the machine that the
app is running on and the shared network directory is NT.

I have tried adding Everyone | Full Control access to the directory in
question but I still get the same failure. If the directory path I
pass to GetFileAttributes is truly local and not a mapped network
drive everything works.

Please help me out! I am getting very frustrated!

Terence Wilson

Felix Kasza [MVP]

unread,
Dec 17, 1997, 3:00:00 AM12/17/97
to

Terence,

> I am using GetFileAttributes to determine the presence of a directory.
> However, I am finding that if the user has mapped a network directory
> to a local drive letter, e.g. l:, GetFileAttributes("l:") returns
> 0xFFFFFFFFF which is classified as a failure.

I'd say the error speaks for itself: a connection was made once but is
not reconnected now. The user belongs neither to the same domain as
the target server, nor does the target have an account with identical
name and password (to the user's home account) set up.

As long as my credentials to the target are OK, this works fine for
me:

#include <windows.h>
#include <stdio.h>
#pragma hdrstop

#define gle GetLastError()

typedef struct _Attr
{
DWORD value;
const char *name;
} Attr;

int main( int argc, char *argv[] )
{
int i, didPrintName;
DWORD att;
static Attr *cura, a[] = {
{ FILE_ATTRIBUTE_ARCHIVE, "FILE_ATTRIBUTE_ARCHIVE" },
{ FILE_ATTRIBUTE_COMPRESSED, "FILE_ATTRIBUTE_COMPRESSED" },
{ FILE_ATTRIBUTE_DIRECTORY, "FILE_ATTRIBUTE_DIRECTORY" },
{ FILE_ATTRIBUTE_HIDDEN, "FILE_ATTRIBUTE_HIDDEN" },
{ FILE_ATTRIBUTE_OFFLINE, "FILE_ATTRIBUTE_OFFLINE" },
{ FILE_ATTRIBUTE_READONLY, "FILE_ATTRIBUTE_READONLY" },
{ FILE_ATTRIBUTE_SYSTEM, "FILE_ATTRIBUTE_SYSTEM" },
{ FILE_ATTRIBUTE_TEMPORARY, "FILE_ATTRIBUTE_TEMPORARY" },
{ 0, NULL }
};

for ( i = 1; i < argc; i ++ )
{
att = GetFileAttributes( argv[i] );
if ( att == 0xffffffff )
{
printf( "\"%s\": error, gle = %lu\n", argv[i], gle );
continue;
}

didPrintName = 0;
for ( cura = &a[0]; cura->value != 0 && cura->name != NULL;
cura ++ )
{
if ( cura->value & att )
{
printf( "%-*s: %s\n", strlen( argv[i] ),
didPrintName? "": argv[i], cura->name );
didPrintName = 1;
}
}

if ( ! didPrintName )
printf( "%s: no attributes\n", argv[i] );
}

return 0;
}

Cheers,
Felix.

--
If you post a reply, kindly refrain from emailing it, too.

Freelance User

unread,
Dec 17, 1997, 3:00:00 AM12/17/97
to

On Wed, 17 Dec 1997 01:37:22 GMT, fel...@mvps.org (Felix Kasza [MVP])
wrote:

>Terence,
>
> > I am using GetFileAttributes to determine the presence of a directory.
> > However, I am finding that if the user has mapped a network directory
> > to a local drive letter, e.g. l:, GetFileAttributes("l:") returns
> > 0xFFFFFFFFF which is classified as a failure.
>
>I'd say the error speaks for itself: a connection was made once but is
>not reconnected now. The user belongs neither to the same domain as
>the target server, nor does the target have an account with identical
>name and password (to the user's home account) set up.
>

Thanks for the quick response Felix, however, I am still a little
confused. If the drive can be mapped using peer-to-peer
networking i.e. workgroups, and I can browse the mapped
drive using explorer, with no password or login required, then
I would expect GetFileAttributes to also have access to the
drive.

I guess what you're saying is GetFileAttributes always tries
to login in order to gain access to a network share, even if
the share has 'world' access?

Thanks for your help!

Terence

Felix Kasza [MVP]

unread,
Dec 17, 1997, 3:00:00 AM12/17/97
to

Terence,

> I guess what you're saying is GetFileAttributes always tries
> to login in order to gain access to a network share

No, that's not what I wanted to say. The login is only done if there
is no current connection to the server targeted by the drive mapping.

Anyway, could you -- just for laughs -- tell me if my code gives the
same result? Thanks!

Terence Wilson

unread,
Dec 17, 1997, 3:00:00 AM12/17/97
to

On Wed, 17 Dec 1997 17:30:30 GMT, fel...@mvps.org (Felix Kasza [MVP])
wrote:

>Terence,


>
> > I guess what you're saying is GetFileAttributes always tries
> > to login in order to gain access to a network share
>
>No, that's not what I wanted to say. The login is only done if there
>is no current connection to the server targeted by the drive mapping.
>
>Anyway, could you -- just for laughs -- tell me if my code gives the
>same result? Thanks!
>
>Cheers,
>Felix.

Hi Felix,
I ran your code and DID NOT get the same results. However,
I have determined the problem and a solution.
My code was running inside a COM component which was loaded
by IIS. IIS uses the IUSR_XXXX (where XXXX is the machine name)
anonymous access login. It was this login that the OS was using to
try and gain access to the network directory I was passing to
GetFileAttributes. The solution was to create a IUSR_XXXX login
on the remote machine, being careful to keep all attributes
the same. When I did this everything worked.

Thanks again for your help,

Terence.


Felix Kasza [MVP]

unread,
Dec 18, 1997, 3:00:00 AM12/18/97
to

Terence,

> My code was running inside a COM component which was loaded
> by IIS.

I am glad you found your fix ... but could I trouble you, the next
time you report a problem, to include such minor details as this one
right at the beginning?

Thanks,

Freelance User

unread,
Dec 19, 1997, 3:00:00 AM12/19/97
to

On Thu, 18 Dec 1997 19:53:44 GMT, fel...@mvps.org (Felix Kasza [MVP])
wrote:

>Terence,


>
> > My code was running inside a COM component which was loaded
> > by IIS.
>
>I am glad you found your fix ... but could I trouble you, the next
>time you report a problem, to include such minor details as this one
>right at the beginning?
>
>Thanks,
>Felix.

You're right, and I usually do.

Thanks once again for your prompt help. It was you
sample code that made the lightbulb go off in my
head.

Cheers,

Terence


0 new messages