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

Re: Unable to remove remembered drives by Roland

Roland
Fri Sep 10 20:18:20 CDT 2004

"Colin Steadman" wrote in message
news:98b101c49728$fbebff10$a301280a@phx.gbl...
: 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!

Is E: a local drive or one you mapped?

http://support.microsoft.com/default.aspx?scid=kb;EN-US;244676

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp



Re: Unable to remove remembered drives by google

google
Mon Sep 13 02:45:27 CDT 2004

>
> Is E: a local drive or one you mapped?
>
> http://support.microsoft.com/default.aspx?scid=kb;EN-US;244676


Drive E: isn't local, so was mapped by the script. Looking at the
article above it suggests using .RemoveNetworkDrive to get rid of it,
which I've already tried, and failed with. It just throws the error:

This network connection does not exist.

But if that was true I should be able to map a drive to it, which I
cant because I get the error:

The local device name is already in use.

If scheduler runs the script. This feels like a scheduler bug to me,
because it cant possibly be mapped and available at the same time.
Especially since the problem goes away completely if I run the script
manually.

Colin