GetLogicalDrives - enumerating mapped network drives

C

Charlie Orford

I have developed a program that is run as a windows service. It uses the
GetLogicalDrives() function to enumerate all the drives on the system. It is
necessary for the program to get a list of mapped network drives in addition
to logical drives.

The GetLogicalDrives() function is able to enumerate mapped network drives
however the problm lies when the program is run as a service. When run as a
service on Windows2000 GetLogicalDrives() is able to return any mapped
network drive that does not require a username/password and any mapped
network drive that uses the same username and password as the service is
running as.

Under WindowsXP (SP1) GetLogicalDrives() does not enumerate any mapped
network drives irrespective of whether or not the drive requires a
username/password or if the service is running as the same user that the
drive requires.

Is this due to a change in which the way services are allowed to interact
with network shares under Windows XP or is something else going on?

TIA,
 
W

William DePalo [MVP VC++]

Charlie Orford said:
I have developed a program that is run as a windows service. It uses the
GetLogicalDrives() function to enumerate all the drives on the system. It is
necessary for the program to get a list of mapped network drives in addition
to logical drives.

A "connection" between a local device and a network resource is with respect
to the logon session active when the connection was made. Services run (or
should) as LocalSystem. Catch 22.
Under WindowsXP (SP1) GetLogicalDrives() does not enumerate any mapped
network drives irrespective of whether or not the drive requires a
username/password or if the service is running as the same user that the
drive requires.

Hmm. I'm not sure I understand. I think what matters is that the thread in
the service that makes the check is running in the context of the user who
made the connection. If the user who made the connection is the same as the
user who "owns" the resource then I'm not sure I understand what is wrong.

You might want to take a look at WNetGetConnection(). It should work if the
service runs under the credentials of the user who made the connection.
Is this due to a change in which the way services are allowed to interact
with network shares under Windows XP or is something else going on?

Well, if the service gets the data you want when installed with a user's
credentials then you might want to take a look at impersonation. Check the
docs for ImpersonateNamedPipeClient() etc.

Regards,
Will
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top