VB6 FileSystemObject works with UNC but not with mapped drives on Win7 PC

Posted on 2010-09-07
Last Modified: 2012-05-10
This is happening on a customer site. I'm trying to use FileSystemObject on a Win7 PC to see if a file exists. If I use the mapped drive, a good filename returns false, UNC returns true.  I also tried an old method:
 Dir(CStr(Filename)) <> ""
Same results.

I tested this at home and I don't have a problem. Yet, I have a workgroup based network.
The customer's Win7 PC is on a domain. I do have administrative rights on that domain but mapped drive still fails. Note: UAC is turned off.

They never had a Vista PC. Just starting to deploy Win7. Previous version (Win XP) does not have the problem.

Looks like some type of Win7 rights issue, but not sure.

Function lbf_FileExist(strFileName As String) As Boolean

Dim ofso

Set ofso = CreateObject("Scripting.FileSystemObject")

        ' Check for file and return appropriate result

        If ofso.FileExists(strFileName) Then

               lbf_FileExist = True


               lbf_FileExist = False

        End If

End function

Open in new window

Question by:askolits
  • 3
  • 3
LVL 21

Expert Comment

ID: 33623764
IF the script runs as administrator, then Administrator (the user) does not see the mapped drives as it runs as a different user. The mapped drives are only for currently logged in user. UNC paths work just find as long as the path exists.

Expert Comment

ID: 33623768
How are you mapping the drive? Windows 7 has some strange behaviors when dealing with "normal" mapped drives sometimes. Try and map it from the server's user's policies (bat file) to see if the error continues.

Author Comment

ID: 33626618
ivanoviola: "The mapped drives are only for currently logged in user. UNC paths work just find as long as the path exists. " 
 Well it's mapped for both types of users and the issue happens both times.
Caracena:"Try and map it from the server's user's policies (bat file) to see if the error continues. "

I'll ask the network admin to look at this posibility.
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

LVL 21

Expert Comment

ID: 33627177
"Well it's mapped for both types of users and the issue happens both times....."
I'm not sure what you mean when you say that.

My point was that if the script runs "As Administrator" while logged in as Joe Blow, the script will not see Joe Blow's mapped drives. That's why it fails.

Author Comment

ID: 33627439
Hmm... Maybe.
I logged in as myself and I am an administrator and it failed. But I didnlt actualy use the "Administrator" username. I'll have to try it and see.
LVL 21

Expert Comment

ID: 33627550
I've run into similar problems when programs that need to run "As Administrator", and use a mapped drive, fails to run correctly. When I change the drive mapping in the config file to a UNC path, all is good.

I think the same problem is happening to your script.

Accepted Solution

askolits earned 0 total points
ID: 33628090
Well, I am going to update my code to use UNC.
I did find some code that will provide the UNC for mapped drives. But, I will probably just used the UNC for now rather than add a bunch of code.

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The recent Microsoft changes on update philosophy for Windows pre-10 and their impact on existing WSUS implementations.
When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup" or a blinking cursor with black screen. A loop for Auto repair will start but fix nothing.  You will be panic as there are no back…
This Micro Tutorial will teach you the basics of configuring your computer to improve its speed. It will also teach you how to disable programs that are running in the background simultaneously. This will be demonstrated using Windows 7 operating…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now