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(flxV ersion.Row , 1) = MyDesktop
'OPEN FILE TO GET DETAILS
Set fso = CreateObject("Scripting.Fi leSystemOb ject")
Set f = fso.GetFile(F:\Program Files\Bank.exe)
'PUT DETAILS INTO FLEXGRID
flxVersion.TextMatrix(flxV ersion.Row , 2) = f.Size
flxVersion.TextMatrix(flxV ersion.Row , 3) = f.DateCreated
'SET TO NOTHING ???????? DOESNT WORK?????
Set f = Nothing
Set fso = Nothing
Else
flxVersion.TextMatrix(flxV ersion.Row , 1) = MyDesktop
flxVersion.TextMatrix(flxV ersion.Row , 2) = "n/a"
flxVersion.TextMatrix(flxV ersion.Row , 2) = "n/a"
End If
'DELETE/DISCONNECT NETWORK DRIVE ??????????
Shell "net use F: /d"
Thanks in advance for any help
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(flxV
'OPEN FILE TO GET DETAILS
Set fso = CreateObject("Scripting.Fi
Set f = fso.GetFile(F:\Program Files\Bank.exe)
'PUT DETAILS INTO FLEXGRID
flxVersion.TextMatrix(flxV
flxVersion.TextMatrix(flxV
'SET TO NOTHING ???????? DOESNT WORK?????
Set f = Nothing
Set fso = Nothing
Else
flxVersion.TextMatrix(flxV
flxVersion.TextMatrix(flxV
flxVersion.TextMatrix(flxV
End If
'DELETE/DISCONNECT NETWORK DRIVE ??????????
Shell "net use F: /d"
Thanks in advance for any help
and here:
If Dir("\\CRAIGDESKTOP\C$\Pro gram Files\Bank.exe") <> "" Then
If Dir("\\CRAIGDESKTOP\C$\Pro
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
i.e.
'CREATES THE MAPPED DRIVE
Shell Environ("ComSpec") & " /c net use F: \\CRAIGDESKTOP\C$", vbHide
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
http://www.computerperformance.co.uk/ezine/ezine3.htm
ASKER
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
if it works will accept your answer
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks very much for your help
No problem, thanks for the points.
ASKER
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
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.
'OPEN FILE TO GET DETAILS
Set fso = CreateObject("Scripting.Fi
Set f = fso.GetFile("\\CRAIGDESKTO