Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't find mapped drives in VB

Status
Not open for further replies.

FletcherJ

Programmer
Mar 24, 2003
4
US
Hi all,

I have tried almost everything to identify if a folder exists on a mapped drive. It's my guess that there is a setting somewhere causing the problem.

Let's say that I have a drive mapped as drive k:. When I use:
My.Computer.FileSystem.DirectoryExists("k:"))
It says that it doesn't exist. Adding a backslash, folder name, etc. doesn't help.

I also tried using System.Management.ManagementScope and System.Management.ObjectQuery and again, they only report that I have 2 drives, C and D.

But if I go to the command window or windows explorer, I can see all the mapped drives. I can open folders, edit files, etc. on any of the mapped drives. I can even copy files back and forth. But VB.NET does not think they exist.

All the docs I have read say that both of these approaches should recognize mapped drives.

As I said, I have to believe that this is just a matter of correcting some setting in VS.NET. But I can't find any documentation in help, on forums, etc. that will tell me which one. Do you know?

Thanks,

Fletcher
 
Try:
' List the drives.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal _
e As System.EventArgs) Handles MyBase.Load
For Each drive As String In Directory.GetLogicalDrives()
lstDrives.Items.Add(drive)
Next drive
End Sub

Or try:

System.IO.Directory.Exists(dir_name)

CIAO~
 
Ok, I did what you suggested. The listbox shows C:\ and D:\ - as I expected (but not what I wanted.) Per your suggestion, I also tried:

Debug.WriteLine(System.IO.Directory.Exists("k:\"))

which returned false in the debug window.

However, if I open windows explorer, I see:

backup (\\fletcher)(K:)

and when I click on it, I see the folders in that share.

Why doesn't VB.NET see that I have drive K: mapped?

I am using Microsoft Visual Studio 2005
Microsoft Visual Basic 2005 - 77718-007-4009332-41823
and
Vista Ultimate with the latest patches.

Again, I am sure it is just a silly setting somewhere.

My code simply recurses the folders and compares the contents of each folder agaist a similar folder on the shared drive. It copies the file to the share if the local version has been changed. But if VB.NET can't see the share, it won't work.

Thanks,

Fletcher
 
What about referencing the share with its proper name "\\pcname\sharename\".

I know that its moving away from what you want, but if that doesn't work then I think that you could report it as a bug.
 
I just ran the following:

MsgBox(System.IO.Directory.Exists("K:\"), vbInformation)

and it returned True

I tried another unmapped drive and it returned false.

Are you using 2.0 framework? I was reading, guess compact framework has an issue with this. You say you are running Vista...maybe a hidden feature of Vista :) I am running XP and tried the above, works fine. Do you have an XP machine to test it on? I don't think it is a setting anywhere.
 
Problem Fixed - or at least kludged....

The problem was with Vista. I was set up to use UAC (User Account Control) which is a good thing. The only problem was that, when I ran the debugger, it ran in administrator mode - essentiall elevating me to the admin user. This should be fine, but the problem is that the admin account that it was using didn't have the drives mapped (although mine did.) When I turned off UAC, I was able to see the drives just fine.

This is only a problem when running the debugger. If I have UAC on and run as an executable (debugging off) then it should work fine.

I wouldn't be surprised if this is the cause of other similar type problems in Vista.

Thanks again for all the comments.

Fletcher
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top