Discussion:
Logon Script will not remove "Remembered Connection" in XP
(too old to reply)
Mike Bailey
2007-08-03 21:31:26 UTC
Permalink
I've been trying to write a simple logon script for a Server 2003/XP
workstation environment.

At this point, I'm past trying anything fancy such as mapping by group
membership, I just want to have everyone map to the same few drives, but
I've run into a problem.

Say someone already has a drive, J:, mapped through XP set to Reconnect.
In my logon script, I have:

wshNetwork.RemoveNetworkDrive "j:"
wshNetwork.MapNetworkDrive "j:","\\myserver\users\shared"

J: is already mapped to something else in XP. The script would not
Remove the drive first. I captured this error "The local device name has
a remembered connection to another network resource." So, since XP is
set to remember the connection, this will not remove it.

I found this information somewhere:
"In addition to the mandatory parameter that specifies the mapped drive
to be removed, the MapNetworkDrive method accepts two additional,
optional, parameters: A Boolean value that, if set to True, specifies
that the method should unmap the drive regardless of whether it is
currently in use. If the value is set to True, the user will no longer
be able to save data to that drive, even if he or she has already opened
a document from there. Instead, the user will have to save the document
to an alternate location.A Boolean value that, if set to True, specifies
that the method should remove the drive mapping from the profile of the
user."

So, I tried this:

wshNetwork.RemoveNetworkDrive "j:",True,True

But it doesnt' work either - it doesn't produce an error, but it doesn't
unmap the drive either.

If I issue a Net Use from the command line, it shows it mapped correctly
there, but My Computer still shows the old mapping - so I guess it's cached.

Can anyone tell me how to over come this? All I want to do is:

1)Check if a drive letter is already mapped to something, if so, unmap it.
2)Map the drive to something new.
3)Have the new mapping correctly displayed in My Computer.

Thanks,
Mike
CreateWindow
2007-08-04 08:26:42 UTC
Permalink
Mike,

This should just work.

Dim WshNet

Set WshNet = WScript.CreateObject("WScript.Network")
WshNet.RemoveNetworkDrive "J:", True, True
Wscript.Sleep(1000)
WshNet.MapNetworkDrive "J:", "\\myserver\users\shared"
Set WSHNet = Nothing

I put a 1 second delay in to allow the network to "settle" before the
reconnect. Might help??

Good luck,

CreateWindow

http://mymessagetaker.com
The While-You-Were-Out program you always wanted.
Stop using those paper phone message pads
make the computer work for you.
http://justpageprobe.com
The FREE Web page utility you always wanted.
Monitor your enterprise Web Servers.
Keep your router connected.
Email your IP to where you need it.
Post by Mike Bailey
I've been trying to write a simple logon script for a Server 2003/XP
workstation environment.
At this point, I'm past trying anything fancy such as mapping by group
membership, I just want to have everyone map to the same few drives, but
I've run into a problem.
Say someone already has a drive, J:, mapped through XP set to Reconnect.
wshNetwork.RemoveNetworkDrive "j:"
wshNetwork.MapNetworkDrive "j:","\\myserver\users\shared"
J: is already mapped to something else in XP. The script would not Remove
the drive first. I captured this error "The local device name has a
remembered connection to another network resource." So, since XP is set
to remember the connection, this will not remove it.
"In addition to the mandatory parameter that specifies the mapped drive to
be removed, the MapNetworkDrive method accepts two additional, optional,
parameters: A Boolean value that, if set to True, specifies that the
method should unmap the drive regardless of whether it is currently in
use. If the value is set to True, the user will no longer be able to save
data to that drive, even if he or she has already opened a document from
there. Instead, the user will have to save the document to an alternate
location.A Boolean value that, if set to True, specifies that the method
should remove the drive mapping from the profile of the user."
wshNetwork.RemoveNetworkDrive "j:",True,True
But it doesnt' work either - it doesn't produce an error, but it doesn't
unmap the drive either.
If I issue a Net Use from the command line, it shows it mapped correctly
there, but My Computer still shows the old mapping - so I guess it's cached.
1)Check if a drive letter is already mapped to something, if so, unmap it.
2)Map the drive to something new.
3)Have the new mapping correctly displayed in My Computer.
Thanks,
Mike
Shenan Stanley
2007-08-04 12:30:00 UTC
Permalink
Post by Mike Bailey
I've been trying to write a simple logon script for a Server 2003/XP
workstation environment.
At this point, I'm past trying anything fancy such as mapping by
group membership, I just want to have everyone map to the same few
drives, but I've run into a problem.
Say someone already has a drive, J:, mapped through XP set to
wshNetwork.RemoveNetworkDrive "j:"
wshNetwork.MapNetworkDrive "j:","\\myserver\users\shared"
J: is already mapped to something else in XP. The script would not
Remove the drive first. I captured this error "The local device
name has a remembered connection to another network resource." So, since
XP
is set to remember the connection, this will not remove it.
"In addition to the mandatory parameter that specifies the mapped
drive to be removed, the MapNetworkDrive method accepts two additional,
optional, parameters: A Boolean value that, if set to True,
specifies that the method should unmap the drive regardless of whether it
is
currently in use. If the value is set to True, the user will no
longer be able to save data to that drive, even if he or she has already
opened a document from there. Instead, the user will have to save the
document to an alternate location.A Boolean value that, if set to True,
specifies that the method should remove the drive mapping from the
profile of the user."
wshNetwork.RemoveNetworkDrive "j:",True,True
But it doesnt' work either - it doesn't produce an error, but it
doesn't unmap the drive either.
If I issue a Net Use from the command line, it shows it mapped
correctly there, but My Computer still shows the old mapping - so I
guess it's cached.
1)Check if a drive letter is already mapped to something, if so,
unmap it. 2)Map the drive to something new.
3)Have the new mapping correctly displayed in My Computer.
Thanks,
Mike
To remove any persistent mappings, more may be necessary.

If (objFSO.DriveExists("j:" = True) Then
objNetwork.RemoveNetworkDrive "j:",True,True
End If

If objFSO.DriveExists("j:") Then
Set objReg =
GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
objReg.DeleteKey HKCU, "Network\" & Left("j:", 1)
Set objReg = Nothing
End If
--
Shenan Stanley
MS-MVP
--
How To Ask Questions The Smart Way
http://www.catb.org/~esr/faqs/smart-questions.html
Mike Bailey
2007-08-06 18:09:12 UTC
Permalink
Post by Shenan Stanley
Post by Mike Bailey
I've been trying to write a simple logon script for a Server 2003/XP
workstation environment.
At this point, I'm past trying anything fancy such as mapping by
group membership, I just want to have everyone map to the same few
drives, but I've run into a problem.
Say someone already has a drive, J:, mapped through XP set to
wshNetwork.RemoveNetworkDrive "j:"
wshNetwork.MapNetworkDrive "j:","\\myserver\users\shared"
J: is already mapped to something else in XP. The script would not
Remove the drive first. I captured this error "The local device
name has a remembered connection to another network resource." So, since
XP
is set to remember the connection, this will not remove it.
"In addition to the mandatory parameter that specifies the mapped
drive to be removed, the MapNetworkDrive method accepts two additional,
optional, parameters: A Boolean value that, if set to True,
specifies that the method should unmap the drive regardless of whether it
is
currently in use. If the value is set to True, the user will no
longer be able to save data to that drive, even if he or she has already
opened a document from there. Instead, the user will have to save the
document to an alternate location.A Boolean value that, if set to True,
specifies that the method should remove the drive mapping from the
profile of the user."
wshNetwork.RemoveNetworkDrive "j:",True,True
But it doesnt' work either - it doesn't produce an error, but it
doesn't unmap the drive either.
If I issue a Net Use from the command line, it shows it mapped
correctly there, but My Computer still shows the old mapping - so I
guess it's cached.
1)Check if a drive letter is already mapped to something, if so,
unmap it. 2)Map the drive to something new.
3)Have the new mapping correctly displayed in My Computer.
Thanks,
Mike
To remove any persistent mappings, more may be necessary.
If (objFSO.DriveExists("j:" = True) Then
objNetwork.RemoveNetworkDrive "j:",True,True
End If
If objFSO.DriveExists("j:") Then
Set objReg =
GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
objReg.DeleteKey HKCU, "Network\" & Left("j:", 1)
Set objReg = Nothing
End If
Thanks. I have a copuple of questions though:

Is nothing else required for this? Do I not have to delare some of this
in Dim's or something? When I tried to include it in my scrip, it
generates an error right at the first line of your code, Char 1. I did
add an additional right parenthesis.

I also got an error on the 6rh line, "set objReg=" I brought up the next
line with it and it seems to fix it.

I don't know vbs, so I can't tell what is missing. Here is the whole
script as I have it now:

===============================================================================
Dim WshNet

'*****************
'MAP COMMON DRIVES
'*****************
'
'Note: U: (User Home directory) is mapped in the user profile in Active
Directory

'I: Drive - myserver\Shares
'************************
If (objFSO.DriveExists("I:" = True)) Then
objNetwork.RemoveNetworkDrive "I:",True,True
End If

If objFSO.DriveExists("I:") Then
Set objReg =
GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
objReg.DeleteKey HKCU, "Network\" & Left("I:", 1)
Set objReg = Nothing
End If

Set WshNet = WScript.CreateObject("WScript.Network")
WshNet.MapNetworkDrive "I:", "\\myserver\shares"
Set WSHNet = Nothing
================================================================================
j***@gmail.com
2007-08-10 03:14:08 UTC
Permalink
In case you're still struggling, you need to replace

Dim WshNet

with

Set objNetwork = WScript.CreateObject("WScript.Network")

(yes, that should be all on one line)

Looks like you're just combining two examples from two different
people.

What that line does is just create an instance of the WScript.Network
object, so you can then call the RemoveNetworkDrive method.

Good Luck!
j***@gmail.com
2007-08-10 03:20:03 UTC
Permalink
Ugh, I just looked closer and it's ALL confused. Here's what you
want:

Set objNet = CreateObject("WScript.Network")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.
\root\default:StdRegProv")

If objFSO.DriveExists("I:") Then
objNet.RemoveNetworkDrive "I:",True,True
End If

If objFSO.DriveExists("I:") Then
objReg.DeleteKey HKCU, "Network\" & Left("I:", 1)
End If

objNet.MapNetworkDrive "I:", "\\myserver\shares"

Set objNet = Nothing
Set objFSO = Nothing
Set objReg = Nothing


I haven't tested this though.
Mike Bailey
2007-08-30 17:00:30 UTC
Permalink
Does the line that starts with \root\ belong on the same line as the
line above - the GerObject
Post by j***@gmail.com
Ugh, I just looked closer and it's ALL confused. Here's what you
Set objNet = CreateObject("WScript.Network")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.
\root\default:StdRegProv")
If objFSO.DriveExists("I:") Then
objNet.RemoveNetworkDrive "I:",True,True
End If
If objFSO.DriveExists("I:") Then
objReg.DeleteKey HKCU, "Network\" & Left("I:", 1)
End If
objNet.MapNetworkDrive "I:", "\\myserver\shares"
Set objNet = Nothing
Set objFSO = Nothing
Set objReg = Nothing
I haven't tested this though.
JRendon
2009-07-10 18:06:52 UTC
Permalink
The key to this issue is the fact that the registry is holding the driv
letter. Hence using "If objFSO.DriveExists("I:") Then objReg.DeleteKe
HKCU, "Network\" & Left("I:", 1) End If ". Adding this extra code di
the trick.

If you do get that error, you can also verify if the drive letter i
there. Launch Regedit (normal disclaimer; if you aren't careful you ca
really muck things up goes here) but launch Regedit and navigate t
"HKCU\Network\" Look for the drive letter in question. If it is there
you'll see where it points and if not - well it's not.

Hope that helps explain why its there and where to find it. Thanks t
the original poster that added that line

--
JRendo
-----------------------------------------------------------------------
JRendon's Profile: http://forums.techarena.in/members/113447.ht
View this thread: http://forums.techarena.in/server-scripting/795099.ht

http://forums.techarena.i
Lanwench [MVP - Exchange]
2009-07-16 13:47:01 UTC
Permalink
Post by JRendon
The key to this issue is the fact that the registry is holding the
drive letter. Hence using "If objFSO.DriveExists("I:") Then
objReg.DeleteKey HKCU, "Network\" & Left("I:", 1) End If ". Adding
this extra code did the trick.
If you do get that error, you can also verify if the drive letter is
there. Launch Regedit (normal disclaimer; if you aren't careful you
can really muck things up goes here) but launch Regedit and navigate
to "HKCU\Network\" Look for the drive letter in question. If it is
there, you'll see where it points and if not - well it's not.
Hope that helps explain why its there and where to find it. Thanks to
the original poster that added that line.
Hi - you're replying to a nonexistent (stale) thread, and you haven't quoted
the original in your reply, so it's unlikely that anyone will know what
you're referring to.

Don't use the icky techarena forums as a means to access the MS public
newsgroups. This is a regular problem with posts from that forum. Nor should
you use Google Groups or any other 'mirror' of the newsgroups. Access them
directly using a newsreader client and msnews.microsoft.com as your NNTP
server. Much, much better.
GergMeister
2009-10-23 18:22:51 UTC
Permalink
Ouch, pretty harsh. The fact that this thread is stale, is reall
irrelevant nowadays. These threads come up as search results, peopl
(such as myself) are searching for a solution, rather than re-postin
the same question over and over, creating new non-stale threads
Secondly, who cares if you quote the previous post, maybe thos
dinosaurs that are using nntp, seriously, like we want a whole thic
client app running just to get to the newsgroups, embrace the ne
technology/methodology. Now, down to my question, in case anybody care
to answer.

Why in this script is everyone using:

objReg.DeleteKey HKCU, "Network\" & Left("I:", 1)

instead of just objReg.DeletKey HKCU, "Network\I". That just seem
crazy, why concatenate and use 'left' on that string

--
GergMeiste
-----------------------------------------------------------------------
GergMeister's Profile: http://forums.techarena.in/members/147858.ht
View this thread: http://forums.techarena.in/server-scripting/795099.ht

http://forums.techarena.i

Loading...