I've setup a VBScript that looks for an unused drive
letter and maps it to another server to allow me to
transfer some files.
The script is completely finished and works perfectly if I
double click on the .VBS file myself and run it. However
when I started the file from the scheduler (using the same
account and password that I used to logon to the server)
its all goes pear shaped.
When I started the script from the scheduler by right
clicking the task and selecting Run it hung. So I right
clicked again and terminated it. I then tried it again a
few more times with a few adjustments to the script.
It turned out that it couldn't map the drive for some
reason and was hanging. The error message was:
"An attempt was made to remember a device that had
previously been remembered"
It seems that while I was debugging my script I was
somehow mapping each free drive that was found (although
you cant see the mapping in My Computer). And it now
appears I cant remove these remembered drives, or map them
again... But only when the script is run from Task
Scheduler.
I've written a function to see whats mapped (see
viewMappings below), and this is what it showed:
d: = True as Data
e: = True as mapped_by_script
f: = True as mapped_by_script
g: = True as mapped_by_script
h: = True as mapped_by_script
i: = True as iApps
j: = True as mapped_by_script
k: = True as mapped_by_script
l: = True as Logs
m: = False
n: = False
o: = True as BACKUP
p: = False
q: = False
r: = False
s: = False
t: = False
u: = False
v: = False
w: = False
x: = False
y: = False
z: = True
All the drive marked as 'mapped_by_script' above have been
mapped by the script when it ran from Task Scheduler.
Looking on the net I've found some code that should remove
these drives, ie:
WshNetwork.RemoveNetworkDrive "E:", False,True
However if I try this with E: I get this error-
This network connection does not exist.
But this cant be True because if I try and map E: I get
this error-
The local device name is already in use.
What on earth is going on here? If I run the script
manually again (not from scheduler), it runs perfectly
again. And will even map drive E: if I tell it too.
Can anyone help? I've been looking at this all day and I
just cannot find a solution, and I dont know what to try
next!
TIA,
Colin
Function getNextFreeDrive()
Dim fso
Dim i
Set fso = Createobject("Scripting.FileSystemObject")
For i = Asc("d") To Asc("z")
If Not fso.driveexists(chr(i)) Then
freeDrive = Ucase(chr(i)) & ":"
Exit For
End If
Next
Set fso = Nothing
Set i = Nothing
End Function
Sub mapDrive()
On Error Resume Next
Dim WshNetwork
Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.MapNetworkDrive freeDrive, ExportFolder
Set WshNetwork = Nothing
End Sub
Function viewMappings()
On Error Resume Next
Dim fso
Dim i
Dim driveListing
Set fso = Createobject("Scripting.FileSystemObject")
For i = Asc("d") To Asc("z")
driveListing = driveListing & Chr(i) & ": = " & _
fso.driveexists(chr(i))
If fso.driveexists(chr(i)) Then
driveListing = driveListing & " as " & _
fso.Drives(chr(i)).VolumeName
End If
driveListing = driveListing & vbcr
Next
SendCDOMail emailTo, emailFrom, "DRIVE LISTING",
driveListing
Set fso = Nothing
Set i = Nothing
End Function