I was wondering if anybody new of a function to detect if a mapped network
drive is connectted or not, like how windows displays 'Disconnected Network
Drive'. I have tried the function 'WNetGetConnection', on a disconnected
drive and it returns NO_ERROR, insead of the error I expected
'ERROR_CONNECTION_UNAVAIL'.
Every time my application starts it scans the drives and when it hits a
network drive that is currently disconneted I get a pause which I would like
to avoid.
Thanks,
Adam
You can use the following API's to test a hardDrive:
IsNetDrive()
GetDriveType()
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/getdrivetype.asp
Hope these information helps,
Kellie.
I've tried all these APIs on my XP SP1 - all they fail to report
disconnected state :(
I've mapped a network drive (for example Q:) and waited until net use reports
it as disconnected. After running the test program I did net use again to
verify that
the drive still is disconnected.
GetDriveTypeW(L"Q:\\") returns 4 = DRIVE_REMOTE
IsNetDrive('Q' - 'A') returns 1 = "network drive that is properly connected"
WNetGetConnectionW returns 0 (success) and correct remote path; extended
error = 0.
If this matters, Q: was mapped to a normal share (non-DFS).
Regards,
--PA
"Pavel A." <pav...@NOwritemeNO.com> wrote in message
news:8CEDFFC5-6EE6-4E78...@microsoft.com...
What happens when you use the API CreateFile() to obtain a handle to
the
mapped netWork drive (Q:\) ?
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/createfile.asp
Kellie.
Try NetUseGetInfo with level 1, then look at the ui1_status field. In
general net.cmd uses Net API so if you wnat to replicate its behavior this
is the place to look first.
--
Eugene
http://www.gershnik.com
Well Eugene... laugh at me but I couldn't make NetUseGetInfo to work at all.
What I tried:
#include <lm.h>
NET_API_STATUS ns = NetUseGetInfo(
NULL, //LMSTR UncServerName: reserved, must be NULL
name, //LMSTR UseName, see below
1, //DWORD Level,
(LPBYTE *)&ui1_struct
);
where name was:
1. "Q:"
2. "Q:\\"
3. L"Q:"
4. L"Q:\\"
In all these cases NetUseGetInfo returned 2250 (This network connection does
not exist.) and ui1_struct pointer = NULL.
Do you have an example on your site?
Regards,
--PA
[...]
> where name was:
> 1. "Q:"
> 2. "Q:\\"
> 3. L"Q:"
> 4. L"Q:\\"
>
> In all these cases NetUseGetInfo returned 2250 (This network
> connection does not exist.) and ui1_struct pointer = NULL.
I don't have access to any sample code right now but I would guess that the
name should be the remote name (L"\\server\share") rather than the local
one. To map local names to the remote ones use NetUseEnum.
> Do you have an example on your site?
Unfortunately not. I have a long backlog of things I want to put there but
too little spare time to do something about it :-(
--
Eugene
http://www.gershnik.com
My wrong... this time Q: was a DFS share.
NetUseGetInfo seems to work only with normal (non-DFS) shares - at least on
my machine (XP SP1 in a domain).
The UseName argument should be like L"Q:".
Then NetUseGetInfo returns correct share name; the status and other data
also look reasonably.
But when Q: is any other type of connection: DFS share or "pseudo-network"
shares created by some software - the call fails and no data is returned.
Command NET USE shows all mappings correctly.
So, this disapproves the statement that NET uses Net... API internally,
or that Net... API give same result as NET comand.
Maybe it was so on earlier Windows versions, but not on XP.
>> Do you have an example on your site?
>
>Unfortunately not. I have a long backlog of things I want to put there but
>too little spare time to do something about it :-(
You write there that the site is under redesign - so i thought I didn't find
the samples...
Regards,
--PA
Only the connections returned by NetUseEnum can be queried by NetUseGetInfo.
For DFS ones you will need to use some DFS specific API. I assume that
NetDfsGetInfo may be what you are looking for.
> Command NET USE shows all mappings correctly.
> So, this disapproves the statement that NET uses Net... API
> internally,
> or that Net... API give same result as NET comand.
> Maybe it was so on earlier Windows versions, but not on XP.
It does use Net API for the normal CIFS connections. As governer of
California likes to say "trust me" ;-) (I am looking at the net.exe source
code now).
The NET USE command first enumerates all resources using WNetEnumResource.
Those that are "Lanman" ones are then further queried by Net API which gives
the status and other things.
--
Eugene
http://www.gershnik.com
Thakyou, 'NetUseGetInfo' does what I needed.
Quick question, does anybody know why 'GetDriveType' and 'WNetGetConnection'
doesn't say that a network drive is disconnected when it is?
Thanks,
Adam
"Eugene Gershnik" <gers...@hotmail.com> wrote in message
news:eHnxiOu6...@TK2MSFTNGP14.phx.gbl...
--PA