Link to home
Start Free TrialLog in
Avatar of CraigBroadman
CraigBroadman

asked on

Closing A FileSystemObject And Mapped Network Drive

See the below code that I have written.

I have created a Mapped Network Drive, then checked a specified file for the Date it was created and the Size using FileSystemObject.

The problem I have is that I cannot Disconnect the network drive using "Net Use strDrive /delete"

I think it is because the FileSystemObject that I have opened still has a hold on that drive as when I run "Net use E: /delete" in DOS it says....

"The device is being accessed by an active process"

The basic code I have is

'CREATES THE MAPPED DRIVE
Shell "net use F: \\CRAIGDESKTOP\C$"

'CHECKS THAT THE FILE EXISTS
If Dir(F:\Program Files\Bank.exe) <> "" Then
           flxVersion.TextMatrix(flxVersion.Row, 1) = MyDesktop

           'OPEN FILE TO GET DETAILS
           Set fso = CreateObject("Scripting.FileSystemObject")
           Set f = fso.GetFile(F:\Program Files\Bank.exe)

           'PUT DETAILS INTO FLEXGRID
           flxVersion.TextMatrix(flxVersion.Row, 2) = f.Size
           flxVersion.TextMatrix(flxVersion.Row, 3) = f.DateCreated
               
           'SET TO NOTHING ???????? DOESNT WORK?????
           Set f = Nothing
           Set fso = Nothing
Else
          flxVersion.TextMatrix(flxVersion.Row, 1) = MyDesktop
          flxVersion.TextMatrix(flxVersion.Row, 2) = "n/a"
          flxVersion.TextMatrix(flxVersion.Row, 2) = "n/a"
End If

'DELETE/DISCONNECT NETWORK DRIVE ??????????
Shell "net use F: /d"


Thanks in advance for any help
Avatar of vinnyd79
vinnyd79

Why map a drive,just try to access the file directly using the UNC path:

           'OPEN FILE TO GET DETAILS
           Set fso = CreateObject("Scripting.FileSystemObject")
           Set f = fso.GetFile("\\CRAIGDESKTOP\C$\Program Files\Bank.exe")
and here:

If Dir("\\CRAIGDESKTOP\C$\Program Files\Bank.exe") <> "" Then
Or you might want to try shelling the command interpretor with the /c switch instead of shelling net use directly.

i.e.
'CREATES THE MAPPED DRIVE
Shell Environ("ComSpec") & " /c net use F: \\CRAIGDESKTOP\C$", vbHide
Avatar of CraigBroadman

ASKER

I have to Map A Drive because there is other things that I need to do apart from this.
I don't think FSO is the problem as you are setting it to Nothing. I think it is the way you are mapping the drive.  Here is a good example of mapping with FSO:

http://www.computerperformance.co.uk/ezine/ezine3.htm
I can disconnect the drive if i take the fso code out. But i will have a look at the link and see what i can do.

if it works will accept your answer

Thanks
ASKER CERTIFIED SOLUTION
Avatar of PaulHews
PaulHews
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks very much for your help
No problem, thanks for the points.
Have just posted another question. Basically looking for other methods of moving a file, other than FSO.

When I am mapping a client machine I copy their current file to a safe folder so that I can copy an updated version into the orginal location.

However, this safe file cannot be deleted by the client as it says another person or program is currently using it.

If you have any ideas for this i would be grateful, another 250 points up for grabs
I'll subscribe there, but it looks like the other experts are already helping you out.